1

Powershell を使用して、serverA から serverB にファイルをコピーしようとしています。どちらのサーバーもホスティング プロバイダーに属しているため、A から B へのファイルのコピーは、ローカル ボックスからいずれかのサーバーへのファイルのコピーに比べて非常に高速です。Powershell を使用して、serverA でリモート コマンドを実行し、ファイルを serverB にコピーできると考えました。これは私が思いついたものです:

$SourceServerName = "serverA"
$SourceContentPath = "\\serverA\c$\testSrc"
$DestinationContentPath = "\\serverB\c$\testDest"

Invoke-Command -ComputerName $SourceServerName -ScriptBlock {param ($SourcePath,$InstallPath) 
                Copy-Item -Path $SourcePath\* -Destination $InstallPath -Recurse
            } -ArgumentList $SourceContentPath, $DestinationContentPath

しかし、「System.Management.Automation.RemoteException: パス 'testDest' へのアクセスが拒否されました。

私は管理者で、両方のボックスで WinRM が適切に構成されています。同じサーバー内でファイルをリモートでコピーしようとすると (つまり、\\serverA\c$\testSrc から \\serverA\c$\testDest に)、すべて正常に動作します。

これを行う適切な方法は何ですか?

4

2 に答える 2

0

サーバーAのコマンドレットは実行されません。

2つの可能な解決策:

最も簡単:

$SourceServerName = "serverA"
$SourceContentPath = "\\serverA\c$\testSrc"
$DestinationContentPath = "\\serverB\c$\testDest"
$cred = Get-Credential # input your username and password of serverB here

Invoke-Command -ComputerName $SourceServerName -ScriptBlock {param ($SourcePath,$InstallPath, $cred) 
            Copy-Item -Path $SourcePath\* -Destination $InstallPath -Recurse -Credential $cred
        } -ArgumentList $SourceContentPath, $DestinationContentPath, $cred

ドメインユーザーソリューション:

ドメインユーザーであり、これら2つのマシンを制御できる場合はEnable-WSManCredSSP、ローカルコンピューターとserverAの両方を介してPowerShellでCredSSPを有効にしてから、を追加-Authentication CredSSPInvoke-Commandます。

于 2012-10-31T11:25:55.587 に答える
0

Invoke-Command現在のユーザー (マシンに現在ログインしているユーザー) の下で実行されます。-CredentialのパラメーターInvoke-Commandをターゲット システムの管理者ユーザーに設定する必要があります。

于 2012-10-30T08:06:09.270 に答える