我正在尝试将一堆服务器上的本地帐户的属性设置为“密码永不过期”。这是我能想到的最好的。我一直在说:
Get-WmiObject : Invalid parameter
At C:\Users\xxxxxx\AppData\Local\Temp\4f06fa1c-61da-4c65-ac0b-a4167d83d51c.ps1:4 char:14
+ Get-WmiObject <<<< -class Win32_UserAccount -Filter "name = 'localaccount'" - ComputerName $server | Set-WmiInstance -Argument @{PasswordExpires = 0}
+ CategoryInfo : InvalidOperation: (:) [Get-WmiObject], ManagementException
+ FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
---------这就是我正在尝试的------------
$servers = Get-Item c:\list.txt
foreach ($server in $servers)
{
Get-WmiObject -class Win32_UserAccount -Filter "name = 'localaccount'" -ComputerName $server | Set-WmiInstance -Argument @{PasswordExpires = 0}
}
谢谢!
答案 0 :(得分:2)
你的错误在于这一行:
$servers = Get-Item c:\list.txt
Get-Item
cmdlet返回FileInfo
个对象,而不是文件的内容。要将内容读入变量,您需要Get-Content
cmdlet。
这应该有效:
Get-Content 'c:\list.txt' | % {
gwmi Win32_UserAccount -Computer $_ -Filter "name='localaccount'" |
Set-WmiInstance -Argument @{PasswordExpires = $false}
}
你也可以像这样进行属性更改(source):
Get-Content 'c:\list.txt' | % {
$account = gwmi Win32_UserAccount -Computer $_ -Filter "name='localaccount'"
$account.PasswordExpires = $false
$account.Put()
}