我编写了一个远程更新计算机的脚本,目前正在将脚本本身的用户名,密码和路径作为参数传递,但它仍然提示我输入用户名和密码以连接到远程计算机。我哪里错了?
[string][ValidateNotNullOrEmpty()]$credentials=$args[0]
[string][ValidateNotNullOrEmpty()]$password=$args[1]
$destination =$args[2]
$destinationHome =$args[3]
$sourcePathBat = $args[4]
$sourcePathZip = $args[5]
$command = "cmd.exe /c \\192.168.50.23\deployment\deploy-smartcheck-kiosk.bat upgrade"
$secPassword = ConvertTo-SecureString -String $password -AsPlainText -Force
$Params = New-Object System.management.automation.PSCredential($credentials, $secPassword)
Write-Host $args[0]
Write-Host $args[1]
Write-Host $args[2]
Write-Host $args[3]
Write-Host $args[4]
Write-Host $args[5]
net use $destination $secPassword /USER:$credentials
Copy-Item -Path $sourcePathBat -Destination $destinationHome;
Copy-Item -Path $sourcePathZip -Destination $destinationHome;
Write-Host "Performing remote command..."
Write-Host $command
Invoke-Command -ComputerName 192.168.50.23 -Credential $Params -ErrorAction Stop -ScriptBlock {
param($command)
Write-Host "Trying to execute remote command ($command)"
Invoke-Expression -Command: "$command"
} -ArgumentList $command
Read-Host -Prompt"按Enter退出..."
更新了脚本并进行了一些更改
这就是我目前正在运行脚本的方式: &安培; '。\ execute-copy-and-command - Copy.ps1' test test2 test3 test4
任何帮助将不胜感激。