java远程执行exe文件,Powershell脚本,用于并行执行远程服务器上的EXE

我编写了一个脚本来并行执行远程服务器上的exe . 但是当exe执行时,我收到了一个错误 . 任何人都可以帮我纠正我的剧本吗?

ForEach ($Computer in Get-Content C:\servers.txt)

{

#To enable winrm if not already

$result = winrm id -r:$computer 2> $null

if ($lastExitCode -eq 0) {

Write-Host "WinRM already enabled on" $computer "..." -ForegroundColor green

} else {

Write-Host "Enabling WinRM on" $computer "..." -ForegroundColor red

\\slcmpx\c$\windows\system32\PsExec.exe \\$computer -accepteula -s C:\Windows\System32\winrm.cmd qc -quiet

if ($LastExitCode -eq 0) {

\\slcmpx\c$\windows\system32\PsService.exe \\$computer restart WinRM

$result = winrm id -r:$computer 2>$null

if ($LastExitCode -eq 0) {Write-Host "WinRM successfully enabled!" -ForegroundColor green}

else {Write-Host "WinRM not enabled!" -ForegroundColor red}

} #end of if

} #end of else

echo "$Computer"

Invoke-Command -ComputerName $Computer -ScriptBlock {Set-ExecutionPolicy unrestricted -force}

$creds = Get-Credential

$PSSession = New-PSSession -ComputerName $Computer -Credential $creds -Authentication Credssp

Invoke-Command -Session $PSSession -ScriptBlock {Invoke-Expression -Command 'c:\windows\WUInstall.exe /install /reboot'}

}

错误:

PS C:\ Users \ sand \ Desktop> . \ pssession.ps1已在server1 ... server1上启用WinRM

命令管道位置1的cmdlet Get-Credential以下参数的提供值:Credential New-PSSession:[server1]连接到远程服务器server1失败,并显示以下错误消息:WinRM客户端无法处理请求 . CredSSP身份验证当前在客户端配置中已禁用 . 更改客户端配置并再次尝试请求 . 还必须在服务器配置中启用CredSSP身份验证 . 此外,必须编辑组策略以允许将凭据委派给目标计算机 . 使用gpedit.msc并查看以下策略:计算机配置 - >管理模板 - >系统 - >凭据委派 - >允许委派新凭证 . 验证是否已启用并配置了适用于目标计算机的SPN . 例如,对于目标计算机名称“myserver.domain.com”,SPN可以是以下之一:WSMAN / myserver.domain.com或WSMAN / * .domain.com有关详细信息,请参阅about_Remote_Troubleshooting帮助主题 . 在C:\ Users \ sand \ Desktop \ pssession.ps1:34 char:20 $ PSSession = New-PSSession -ComputerName $ Computer -Credential $ creds -Aut ... ~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ OpenError:(System.Manageme .... RemoteRunspace:RemoteRunspace)[New-PSSession],PSRemotin gTransportException FullyQualifiedErrorId:-2144108126,PSSessionOpenFailed Invoke-Command:无法验证参数'Session'的参数 . 参数为null或空 . 提供非null或空的参数,然后再次尝试该命令 . 在C:\ Users \ sand \ Desktop \ pssession.ps1:35 char:32 Invoke-Command -Session $ PSSession -ScriptBlock {Invoke-Expression -Comma ... ~~~~~~~~~~ CategoryInfo:InvalidData: (:) [Invoke-Command],ParameterBindingValidationException FullyQualifiedErrorId:ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeCommandCommand

PS C:\ Users \ sand \ Desktop>

Note: WUInstall.exe 是通过联系每个地区的通信WSUS服务器来安装补丁的工具

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值