Windows Server Backupではマウントされている仮想ボリュームはバックアップされない の運用をするための、特定フォルダ内にあるVHDファイルをまとめてattach,detachするスクリプトです。
まとめてattachするスクリプト
3 | 指定されたフォルダにあるVHDファイルを全部attachします。 |
18 | $erroractionpreference = "SilentlyContinue" |
19 | remove-item ( join-path $myPath "VHDAttach.txt" ) |
20 | $erroractionpreference = "Continue" |
22 | $scriptFilePath = ( join-path $myPath "VHDAttach.txt" ) |
23 | "select vdisk file=`" " + $_.fullname + " ` "" | Out-File -FilePath $scriptFilePath -Append -Encoding Default |
24 | "attach vdisk" | Out-File -FilePath $scriptFilePath -Append -Encoding Default |
27 | $logFilePath = ( Join-Path $logDirPath "VHDAttach.log" ) |
28 | Get-Date >> $logFilePath |
29 | diskpart /s ( join-path $myPath "VHDAttach.txt" ) >> $logFilePath |
まとめてdetachするスクリプト
3 | 指定されたフォルダにあるVHDファイルを全部detachします。 |
19 | $erroractionpreference = "SilentlyContinue" |
20 | remove-item ( join-path $myPath "VHDDetach.txt" ) |
21 | $erroractionpreference = "Continue" |
24 | $scriptFilePath = ( join-path $myPath "VHDDetach.txt" ) |
25 | "select vdisk file=`" " + $_.fullname + " ` "" | Out-File -FilePath $scriptFilePath -Append -Encoding Default |
26 | "detach vdisk" | Out-File -FilePath $scriptFilePath -Append -Encoding Default |
29 | $logFilePath = ( Join-Path $logDirPath "VHDDetach.log" ) |
30 | Get-Date >> $logFilePath |
31 | diskpart /s ( join-path $myPath "VHDDetach.txt" ) >> $logFilePath |
オプション指定:
-myPath … VHDファイルがあるフォルダを指定します。
-logDirPath … 動作ログを出力するフォルダを指定します。