リモートのコンピュータ(192.168.2.10)に証明書をコピーしてインポートするPowerShellスクリプトの例を以下に示します。この例では、Copy-Item
コマンドレットと Invoke-Command
コマンドレットを使用しています。
# ローカルPCのファイルパス
$localCerPath = "C:\Path\To\Your\Certificate.cer"
# リモートPCのIPアドレス
$remoteComputer = "192.168.2.10"
# リモートPCへ証明書をコピー
Copy-Item -Path $localCerPath -Destination "\\$remoteComputer\C$\Path\To\Destination\" -Credential (Get-Credential)
# リモートPCへのPowerShellセッションの確立
$remoteSession = New-PSSession -ComputerName $remoteComputer -Credential (Get-Credential)
# リモートPC内で証明書をインポート
Invoke-Command -Session $remoteSession -ScriptBlock {
$cerPath = "C:\Path\To\Destination\Certificate.cer"
Import-Certificate -FilePath $cerPath -CertStoreLocation "Cert:\LocalMachine\Root"
}
# リモートセッションのクローズ
Remove-PSSession $remoteSession
このスクリプトでは、まずローカルPCからリモートPCへのファイルのコピーを行います。その後、リモートPC内でPowerShellセッションを確立し、証明書をインポートします。リモートPCにアクセスするためには適切な資格情報が必要です。-Credential
パラメータで資格情報を指定し、Get-Credential
コマンドレットを使用してユーザー名とパスワードを入力します。