LoginSignup
0
2

More than 5 years have passed since last update.

powershellに関する備忘録

Posted at

windowsで簡単なプログラム作成する時に、
デフォでインストールされているpowershellを使用するのが便利ですね。


# コマンドレットのエラーもtrapでキャッチできるようにする
# デフォルトはcontinue
$ErrorActionPreference = "Stop"

trap{
        ##処理

        continue
}      

trapでキャッチして、continueすることで無視して続けることができる。

文字列のNULLチェック

#NULLでなければ・・・
if(![string]::IsNullOrEmpty($vcn)){

}

テキスト検索

# テキスト検索
$result =  Select-String -Path [ファイルパス] -SimpleMatch  [検索ワード] | % { $_.Line } 

$resultに検索結果が格納される

空ファイルの作成

# 空ファイル作成
Clear-Content  error_word.txt

CSVファイルの読み込み

Import-Csv [CSVファイルパス] | ForEach-Object{

}

0
2
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
0
2