function GpuPreference
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory = $true)]
[string[]]$app
)
$app = $app.Replace("`"", "").Split(",").Trim()
# $app.GetType()
New-ItemProperty -Path HKCU:\Software\Microsoft\DirectX\UserGpuPreferences -Name $app -PropertyType String -Value "GpuPreference=2;" -Force
}
$app = Read-Host -Prompt " "
GpuPreference $app
Function works properly but not with New-ItemProperty:
Console output:
Type paths: "D:\", "D:\1", "D:\2" New-ItemProperty : Cannot convert "System.String[]" to the type "System.String" required bt parameter "Name". Specified metod is not supported. line:12 char:83 + ... KCU:\Software\Microsoft\DirectX\UserGpuPreferences -Name $app -Proper ... + ~~~~ + CategoryInfo : InvalidArgument: (:) [New-ItemProperty], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.NewItemPropertyCommand
How should the function be modified, if I want to set paths as parameters, separated in commas and taken in quotes?
$app
is a string array whileName
parameter expects a single string to be passed as input. That's why you are getting this error. – Chetan