添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Hi all, I am trying to get this script to prompt for a language, can’t seem to get it to work.

$UserLanguageList = New-WinUserLanguageList -Language "en-US"
$UserLanguageList.Add=(Read-Host -Prompt "enter a language")
Set-WinUserLanguageList -LanguageList $UserLanguageList

I get the following error:

Exception setting “Add”: “Cannot set the Value property for PSMemberInfo object of type “System.Management.Automation.PSMethod”.”
At C:\Users\xscott\Desktop\ZAY\PS-BATCH and MDT Scripts\Untitled3.ps1:2 char:1

  • $UserLanguageList.Add=(Read-Host -Prompt “enter a language”)
  • CategoryInfo : NotSpecified: (:slight_smile: , SetValueInvocationException
  • FullyQualifiedErrorId : ExceptionWhenSetting
  • You can’t put the Read-Host expression within the .Add() method, because it expects a value rather than an expression that it can evaluation.

    Try this:

    $UserLanguageList = New-WinUserLanguageList -Language "en-US"
    $AdditionalLanguage = Read-Host -Prompt "enter a language"
    $UserLanguageList.Add($AdditionalLanguage)
    Set-WinUserLanguageList -LanguageList $UserLanguageList
    

    The language list is a sub-type of a List (T) class. Get-Member doesn’t list all of the available methods for list objects, but the documentation is here:

    https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1?redirectedfrom=MSDN&am

    Zay1967:

    Thanks for teaching me to fish, worked like a charm. One more ask, when I run it, it prompts if I want to confirm (Continue with this operation). Is there a way to suppress that, or input a default response?

    Usually that happens if a command specifies the -Confirm parameter. Does your script use it anywhere?You can stop the confirmation message by omitting the -Confirm parameter or explicitly by setting it to $false.

    Set-WinUserLanguageList -LanguageList $UserLanguageList -Confirm:$false
    

    You can also change value of the $ConfirmPreference preference variable.