基本的なPowershellのコーディング
$date = Get-Date -Format "yyyyMMddHHmmss"
$script_file="c:\work\20210711\log\test2$date.log"
$result_file="C:\work\20210711\resulttest2$date.txt"
function START_DISP{
echo "START" >> $script_file 2>&1
}
function END_DISP{
echo "END" >> $script_file 2>&1
}
START_DISP
Get-command | Out-File $result_file -Append
if ($? -eq "True" ){
Write-Output "OK" >> $script_file 2>&1
} else {
Write-Output "NG" >> $script_file 2>&1
}
$result = Test-Path $result_file
if ($result -eq "True"){
Write-Output "ファイル取得に成功" >> $script_file
} else {
Write-Output "ファイル取得に失敗" >> $script_file
}