![](https://powershell.work/wp-content/themes/cocoon-master/images/b-woman.png)
PowerShellで
・フォルダをコピー
できます!
コード
ここでは例として
・デスクトップ配下のフォルダ「aiueo」を
・フォルダ「folder_001」へコピー
します。
![](https://powershell.work/wp-content/uploads/2022/07/ps_copy_folder_001.png)
# コピーするフォルダのフォルダパス
$targetFolderPath="C:\Users\user\Desktop\aiueo"
# コピー先のフォルダ
$destFolderPath="C:\Users\user\Desktop\folder_001"
$ws = New-Object -ComObject Wscript.Shell
try
{
# フォルダをコピー(既に存在する場合は上書き)
Copy-Item -Force -Recurse $targetFolderPath $destFolderPath -ErrorAction Stop
$ws.popup("フォルダをコピーしました。")
}
catch
{
$ws.popup("エラー : " + $PSItem)
}
実行結果
フォルダをコピーできました。
![](https://powershell.work/wp-content/uploads/2022/07/ps_copy_folder_002.png)
![](https://powershell.work/wp-content/uploads/2022/07/ps_copy_folder_003.png)
参考①
ファイルのコピーもできます。
詳細は以下の記事をご確認ください。
参考②
上記のコードで使用した以下の詳細は、公式サイトをご確認ください。
●「Copy-Item」コマンドレット
●例外処理について