没有凭据对话框的 运行 脚本问题
Issues with running script without credentials dialog box
我正在尝试 运行 通过 powershell 脚本创建计算机名并将该计算机放置在 AD 中的正确 OU 中。唯一的问题是我需要为此输入凭据,但我想这样做而不必在 powershell 凭据对话框中输入凭据。
我使用了 System.Management.Automation.PSCredential,但那显然是给我的对话框。
$secpasswd = ConvertTo-SecureString 'xxxxxx' -AsPlainText -Force
$mycreds = New-Object System.Managemnet.Automation.PSCredential("xxxx", $secpasswd)
尝试在不弹出对话框的情况下使用上面的代码
New-Object : Cannot find type [System.Managemnet.Automation.PSCredential]: verify that the assembly containing this type is loaded.
At line:2 char:12
+ $mycreds = New-Object System.Managemnet.Automation.PSCredential("xxxx ...
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
+ FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
您的代码似乎有错别字:Managemnet
应该是 Management
,如 System.Management.Automation
。这就是抛出错误的原因。
但是,没有必要使用 PSCredential
的完整定义。请改用以下内容:
$secpasswd = ConvertTo-SecureString 'xxxxxx' -AsPlainText -Force
$mycreds = New-Object PSCredential("xxxx", $secpasswd)
这不显示对话框。
您在 "Managemnet" 上打错了字。应该是-
$mycreds = New-Object 系统.管理.Automation.PSCredential("xxxx", $secpasswd)
我正在尝试 运行 通过 powershell 脚本创建计算机名并将该计算机放置在 AD 中的正确 OU 中。唯一的问题是我需要为此输入凭据,但我想这样做而不必在 powershell 凭据对话框中输入凭据。
我使用了 System.Management.Automation.PSCredential,但那显然是给我的对话框。
$secpasswd = ConvertTo-SecureString 'xxxxxx' -AsPlainText -Force
$mycreds = New-Object System.Managemnet.Automation.PSCredential("xxxx", $secpasswd)
尝试在不弹出对话框的情况下使用上面的代码
New-Object : Cannot find type [System.Managemnet.Automation.PSCredential]: verify that the assembly containing this type is loaded. At line:2 char:12 + $mycreds = New-Object System.Managemnet.Automation.PSCredential("xxxx ... +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
您的代码似乎有错别字:Managemnet
应该是 Management
,如 System.Management.Automation
。这就是抛出错误的原因。
但是,没有必要使用 PSCredential
的完整定义。请改用以下内容:
$secpasswd = ConvertTo-SecureString 'xxxxxx' -AsPlainText -Force
$mycreds = New-Object PSCredential("xxxx", $secpasswd)
这不显示对话框。
您在 "Managemnet" 上打错了字。应该是-
$mycreds = New-Object 系统.管理.Automation.PSCredential("xxxx", $secpasswd)