今日、私は同じ問題を抱えており、解決策を見つけることができず、WEBで検索してトンの記事を読んでいますが、成功していません。リモート マシンで PowerShell スクリプトを実行する際の問題。このスクリプトをローカルで実行すると動作しますが、リモートでは動作しません。
これは私の完全な話です。
サーバ: Windows 2008 R2 SP1 + 最新のアップデート FW – オフ UAC – オン : - ユーザー アカウント制御: 組み込みの管理者アカウントに管理者承認モードを使用する – 無効にする - ユーザー アカウント制御: セキュリティで保護されたデスクトップを使用せずに、UIAccess アプリケーションが昇格を要求できるようにします。– 無効にする - ユーザー アカウント制御: 管理者承認モードでの管理者の昇格プロンプトの動作 – プロンプトなしで昇格 - ユーザー アカウント制御: アプリケーションのインストールを検出し、昇格を求める – 無効にする ドメイン: hardening.com ホスト名: qwerty12345 インストールされている PowerShell のバージョン: PS C:\Windows\system32> $PSVersionTable 名前 値 ---- ----- CLR バージョン 2.0.50727.5420 ビルドバージョン 6.1.7601.17514 PSバージョン2.0 WSManStackバージョン 2.0 PSCompatibleVersions {1.0、2.0} シリアル化バージョン 1.1.0.1 PSRemotingProtocolバージョン 2.1 クライアント: Windows 2008 R2 + 最新のアップデート FW – オフ UAC – オン : - ユーザー アカウント制御: 組み込みの管理者アカウントに管理者承認モードを使用する – 無効にする - ユーザー アカウント制御: セキュリティで保護されたデスクトップを使用せずに、UIAccess アプリケーションが昇格を要求できるようにします。– 無効にする - ユーザー アカウント制御: 管理者承認モードでの管理者の昇格プロンプトの動作 – プロンプトなしで昇格 - ユーザー アカウント制御: アプリケーションのインストールを検出し、昇格を求める – 無効にする ドメイン: systemqa.com インストールされている PowerShell のバージョン: PS C:\> $PSVersionTable 名前 値 ---- ----- CLR バージョン 2.0.50727.4952 ビルドバージョン 6.1.7600.16385 PSバージョン2.0 WSManStackバージョン 2.0 PSCompatibleVersions {1.0、2.0} シリアル化バージョン 1.1.0.1 PSRemotingProtocolバージョン 2.1 • PowerCLIもインストールされたクライアントに 1. サーバーには、次の内容のファイル "C:\Windows\Temp\ ConfigurationWinRM.ps1" があります。 winrm set winrm/config/client `@`{TrustedHosts=`"`*`"`} winrm set winrm/config/winrs '@{MaxShellsPerUser="100"}' 2. 私の使命は、これらのスクリプトをリモートの「サーバー」マシンで実行します。 3. 「クライアント」マシンから次のスクリプトを実行しましたが、常に同じエラーが発生します。 メッセージ = アクセスが拒否されました。 エラー番号: -2147024891 0x80070005 を。例 1: $domainCrd = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "$domainUser@$domainNameFQDN",$domainPASS $ComputerName = "qwerty12345.hardening.com" 起動コマンド -ComputerName $ComputerName -Credential $domainCrd -ScriptBlock { $FileName = "ConfigurationWinRM.ps1" $ItemLocation = "C:\Windows\Temp\" powershell -NoProfile -Command ". $ItemLocation$FileName" } b. 例 2: $ComputerName = "qwerty12345.hardening.com" $securePassword = ConvertTo-SecureString "************" -AsPlainText -force $credential = New-Object System.Management.Automation.PsCredential("$domainName\$domainUser",$securePassword) Invoke-Command -ComputerName $ComputerName -ScriptBlock { $FileName = "ConfigurationWinRM.ps1" $ItemLocation = "C:\Windows\Temp\" powershell -Command ". $ItemLocation$FileName" } -クレデンシャル $credential c. 例 3: [スクリプトブロック] $global:runFile = { $FileName = "ConfigurationWinRM.ps1" ### $ItemLocation = "C:\Windows\Temp\" $ItemLocation = "$env:windir\Temp\" & "$アイテムの場所$ファイル名" } RemotePowerShellConnect ドメイン $runFile WSManFault + CategoryInfo : NotSpecified: (WSManFault:String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError メッセージ = アクセスが拒否されました。 エラー番号: -2147024891 0x80070005 アクセスが拒否されました。 WSManFault メッセージ = アクセスが拒否されました。 エラー番号: -2147024891 0x80070005 アクセスが拒否されました。 [vSphere PowerCLI] C:\> $error[0] | フォーマットリスト * -強制 PSMessageDetails : OriginInfo : qwerty12345.hardening.com 例外: System.Management.Automation.RemoteException: エラー番号: -2147024891 0x80070005 アクセスが拒否されました。 ターゲットオブジェクト: CategoryInfo : NotSpecified: (:) []、RemoteException FullyQualifiedErrorId : NativeCommandErrorMessage エラーの詳細: InvocationInfo : PipelineIterationInfo : {} d. 例 4: [vSphere PowerCLI] C:\> [ScriptBlock] $global:www = { $FileName = "ConfigurationWinRM.ps1" $ItemLocation = "C:\Windows\Temp\" function Invoke-Admin() { param ( [string]$program = $(throw "プログラムを指定してください" ), [文字列]$argumentString = "", [スイッチ] $waitForExit ) $psi = 新しいオブジェクト "Diagnostics.ProcessStartInfo" $psi.FileName = $program $psi.Arguments = $argumentString $psi.Verb = "runas" $proc = [Diagnostics.Process]::Start($psi) もし ( $waitForExit ) { $proc.WaitForExit(); } } Write-Host -ForegroundColor Green "Invoke-Admin powershell $ItemLocation$FileName" Invoke-Admin powershell $ItemLocation$FileName } [vSphere PowerCLI] C:\> RemotePowerShellConnect ドメイン $www セッション状態: オープン セッションの可用性: 利用可能 ランニング サービスは実行中です... VM リモート PowerShell に接続します... Invoke-Admin powershell C:\Windows\Temp\ConfigurationWinRM.ps1 [vSphere PowerCLI] C:\> [vSphere PowerCLI] C:\> 何も起こらない!!!!! リモート「サーバー」マシンに更新はありません!!! e. 例 5: .\tmp\psexec -d \\$hostNAME -u $domainName\$domainUser -p $myPASS cmd /C START /WAIT powershell %windir%\Temp\ConfigurationWinRM.ps1 PsExec v1.98 - プロセスをリモートで実行 Copyright (C) 2001-2010 マーク・ルシノビッチ Sysinternals - www.sysinternals.com cmd はプロセス ID 3860 で qwerty12345 で開始されました。 [vSphere PowerCLI] C:\> 何も起こらない!!!!! リモート「サーバー」マシンに更新はありません!!!