0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

仮PowerShellで証明書のインポート

Posted at

リモートのコンピュータ(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 コマンドレットを使用してユーザー名とパスワードを入力します。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?