Skip to content

Instantly share code, notes, and snippets.

@hidsh
Created July 8, 2022 02:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hidsh/d85e92be4c8db2c94cf968f2fcee1ae4 to your computer and use it in GitHub Desktop.
Save hidsh/d85e92be4c8db2c94cf968f2fcee1ae4 to your computer and use it in GitHub Desktop.
コマンドライン(powershell)で Windows 10 の復元ポイントを作成
# コマンドライン(powershell)で Windows 10 の復元ポイントを作成
#
$comment = Read-Host "コメント"
if([string]::IsNullOrEmpty($comment)) {
$comment = "変更"
}
#Write-Output $comment
try {
Checkpoint-Computer -Description $comment -ErrorAction Stop
}
catch [System.Management.ManagementException] {
Write-Output $_.Exception
}
finally {
# 開いたままにする
$host.UI.RawUI.ReadKey()
}
@hidsh
Copy link
Author

hidsh commented Jul 8, 2022

スタートメニューから実行する場合は下のようにショートカットを作って、C:\ProgramData\Microsoft\Windows\Start Menu\Programs に入れておく。

powershell でこのファイルを走らせるので、ショートカットのリンク先の先頭にpowershell を追加しておくのを忘れずに。

image

@hidsh
Copy link
Author

hidsh commented Jul 8, 2022

あと、前回復元ポイントを作成して1時間以内に再度作成する場合は下記のようにエラー(例外)が発生して作成できないので注意。

Checkpoint-Computer : アクセスは拒否されました
発生場所 D:\pgm\mk-fukugen-point.ps1:11 文字:2
+     Checkpoint-Computer -Description $comment -ErrorAction Stop
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Checkpoint-Computer]、ManagementException
    + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.CheckpointComputerCommand

@hidsh
Copy link
Author

hidsh commented Jul 8, 2022

動いてないっぽい

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment