0
我正在尝试将远程服务器身份验证添加到PS1批处理文件脚本中。PowerShell v1脚本提示输入密码
所以我可以这样做:
Copy-Item $src $destination -Credential $Creds
我创建了一个密码文件,对于现在在同一目录中的脚本。它只是包含密码字符串。
引起提示行:
Read-Host -AsSecureString | ConvertFrom-SecureString | Out-File password.txt
当我去掉Read-host命令,迅速消失和脚本按预期执行。
问题 什么是做远程服务器验证的正确方法?
下面是在脚本的背景下,新代码:
[...]
if(-not(Test-Path $destination)){mkdir $destination | out-null}
Read-Host -AsSecureString | ConvertFrom-SecureString | Out-File password.txt
$PW = Get-Content password.txt | ConvertTo-Securestring
$Creds = New-Object -Typename System.Management.Automation.PSCredential -Argumentlist "SERVER02\Administrator",$PW
ForEach ($sourcefile In $(Get-ChildItem $source | Where-Object { $_.Name -match "Daily_Reviews\[\d{1,12}-\d{1,12}\].journal" }))
{
[...]
Copy-Item $src $destination -Credential $Creds
[...]
}
您是否试图在没有提示的情况下读取密码?或者您使用的身份验证不起作用? – 2013-04-11 17:05:50