【发布时间】:2013-10-09 23:37:47
【问题描述】:
我已经在 Powershell 2.0 中解决了这个问题,但需要移植到 Perl 5.10 才能使用旧版应用程序。
我的 Windows 服务帐户凭据无法以 $Account 和 $Password 的形式交互登录传递给 perl 脚本。 $Account 变量包括域名和 AD 用户帐户名。我的 Powershell 解决方案(单线)是:
PS C:\> New-PsSession -Credential (new-object -typename System.Management.Automation.PSCredential -argumentlist '$Account', (ConvertTo-SecureString '$Password' -AsPlainText -Force)); exit-PsSession;
如果创建了新的 PsSession,则帐户验证通过,我将输出到 STDOUT,如下所示:
Id Name ComputerName State ConfigurationName Availability
-- ---- ------------ ----- ----------------- ------------
1 Session1 localhost Opened Microsoft.PowerShell Available
如果验证失败,我会得到这样的输出到 STDERR:
[localhost] Connecting to remote server failed with the following error message
: Access is denied. For more information, see the about_Remote_Troubleshooting
Help topic.
+ CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:Re
moteRunspace) [], PSRemotingTransportException
+ FullyQualifiedErrorId : PSSessionOpenFailed
我可以在我的程序中解析这些结果。我想在 Windows 上的 Perl 5.10 中做类似的事情。我要做的就是测试密码是否适用于帐户,同时记住交互式登录被拒绝。有什么想法吗?
【问题讨论】:
标签: perl powershell