Skip to content

Instantly share code, notes, and snippets.

@RYLSnmm
Created February 15, 2021 10:33
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 RYLSnmm/986b7aa6b6439d164d1a871762fc0dc3 to your computer and use it in GitHub Desktop.
Save RYLSnmm/986b7aa6b6439d164d1a871762fc0dc3 to your computer and use it in GitHub Desktop.
フォルダ共有を使ってリモートコマンド実行
$bat = $args[0]
while ($true) {
if (Test-Path $bat -PathType Leaf) {
$ts = Get-Date -Format "yyyy/MM/dd HH:mm"
"### ${ts} | ${bat}" >> "$bat.log"
& $bat 2>&1 >> "$bat.log"
mv $bat "$bat.done"
}
sleep -s 1
}

使い方

PowerShell で

& path\to\autorun.ps1 path\to\batfile

実行内容

指定のパスを毎秒チェックする
ファイルがあればコマンドとして実行
想定してるのは bat ファイル

実行したら .done 付きの名前にリネームする
ログは .log 付きの名前で出力

説明

指定パスを共有フォルダの内側にする
別のパソコンで bat ファイルを指定のパスに配置
リモートでコマンド実行できる

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