リモートサーバーにexeを並列で実行するスクリプトを作成しました。しかし、exeが実行されているとき、私はエラーが発生しています。誰でも私のスクリプトを修正するのを助けることができますか?リモートサーバー上でEXEを並列に実行するPowershellスクリプト
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 \ユーザー砂\デスクトップ> \ pssession.ps1 のWinRMすでにserver1上の有効... サーバー1
コマンドレットは、Get-資格コマンドパイプラインで。 position 1 資格情報 New-PSSession:[server1]リモートサーバーserver1に接続できませんでした。次のエラーメッセージが表示されます。WinRM クライアントは要求を処理できませんst。 CredSSP認証は、クライアント構成で現在無効になっています。クライアント構成を に変更し、要求を再試行してください。 CredSSP認証もサーバ の設定で有効にする必要があります。また、グループポリシーを編集して、対象コンピュータへの資格情報の委任を許可する必要があります。 gpedit.mscを を使用し、以下の方針を見て:コンピュータの構成] - > [管理用テンプレート] - > [システム] - > [資格情報 委任 - >新鮮な資格情報の委任を許可。対象のコンピュータに適切なSPN( )を有効にして構成されていることを確認します。 * WSMAN/myserver.domain.comまたはWSMAN/domain.comを詳細については、about_Remote_Troubleshootingの ヘルプを参照してください。たとえば、ターゲットコンピュータ名「myserver.domain.com」のために、SPNは次 のいずれかになります。トピック。 Cで :\ Users \ユーザー砂\デスクトップ\のpssession.ps1:34文字:20 + $のPSSession =新-PSSessionは-ComputerName $コンピュータ-Credential $のcredsを-Aut ... + ~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~ + CategoryInfo:OpenError:(System.Manageme .... RemoteRunspace:RemoteRunspace)[新-PSSessionコマンド]、PSRemotin gTransportException + FullyQualifiedErrorId:-2144108126は、 Invoke-CommandコマンドをPSSessionOpenFailed:パラメータ「セッションに引数を検証することはできません'引数がnullまたは空です。ヌルまたは空でない引き数 を指定して、コマンドを再試行してください。 Cで :\ Users \ユーザー砂\デスクトップ\のpssession.ps1:35文字:32 + Invoke-Commandコマンド-Session $のPSSession -ScriptBlockは{~~~~~~~~~ ... -Comma +を表現起動〜 + CategoryInfo:InvalidData:(:) [Invoke-Commandコマンド]を、ParameterBindingValidationException + FullyQualifiedErrorId:ParameterArgumentValidationError、Microsoft.PowerShell.Commands.InvokeCommandCommand
PS C:\ Users \ユーザー>
ノート砂\デスクトップ:WUInstall.exe
は、各地域の対応するWSUSサーバーに連絡してパッチをインストールするツールです
を-cred。 –
私はドメイン管理者のアクセス権を持っており、RDP経由でサーバに接続したときにそれを行うことができます – Sandeep