我有200台域计算机,我需要更改主机名并在单击时重新加入到域。
Powershell.exe "-ExecutionPolicy Bypass Add-Computer -DomainName <Domain Name> -ComputerName <Old_ComputerName> -NewName <New_ComputerName> -$credential = New-Object System.Management.Automation.PSCredential($username = "<Domain\User ID>", ($password = <Password> | ConvertTo-SecureString -asPlainText -Force))" net user Administrator <Password>但是,在cmd中以提升的权限执行上述脚本时。我得到了下面的错误。
At line:1 char:206
+ ... ement.Automation.PSCredential($username = Domain\User ID, ($passw ...
+ ~
Missing argument in parameter list.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingArgument 我们正在寻找一个单行命令来执行上面的操作。
发布于 2020-05-29 05:20:06
此命令语法不正确。
这样做是一个脚本并运行脚本(使用PS2EXE工具作为exe交付给用户),因此不需要批处理文件。
# Begin Script
$AddComputerSplat = @{
DomainName = <Domain Name>
ComputerName = <Old_ComputerName>
NewName = '<New_ComputerName>'
$credential = New-Object System.Management.Automation.PSCredential($username = 'Domain\UserID',
($password = 'Password' | ConvertTo-SecureString -asPlainText -Force))
}
Add-Computer @AddComputerSplat获取-本地用户 https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.localaccounts/get-localuser?view=powershell-5.1 新本地用户 https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.localaccounts/new-localuser?view=powershell-5.1 Get-LocalGroupMember https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.localaccounts/get-localgroupmember?view=powershell-5.1 添加-本地组成员 https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.localaccounts/add-localgroupmember?view=powershell-5.1
# End Script或者,如果您只想使用cmd.exe并调用consoelhost,那么这种方法应该适用于您。
$Command = 'Add-Computer -DomainName <Domain Name> -ComputerName <Old_ComputerName> -NewName <New_ComputerName> -$credential = New-Object System.Management.Automation.PSCredential($username = "<Domain\User ID>", ($password = <Password> | ConvertTo-SecureString -asPlainText -Force))"'
powershell -ArgumentList '-NoExit', 'NoProfile', '-ExecutionPolicy Bypass', "-Command &{ $ConsoleCommand }"https://stackoverflow.com/questions/62068509
复制相似问题