1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Powershellでの日付け取得、ファイル出力

Posted at

基本的な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
}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?