PowerShell Tips

日々の業務で仕入れたPowerShellの知識を書き残していく。
随時更新します。

文字列操作

文字列内で変数の展開

波括弧{ }で括らないと、変数名が_fuga部分までと認識される。

$strA = "hoge"
Write-Output ${strA}_fuga

実行結果

hoge_fuga

文字列内で変数の展開をしない

出力したい文字列をシングルクォート(')で括ると、その部分がそのまま出力される。

$strA = "hoge"
Write-Output '${strA}_fuga'
Write-Output "${strA}_fuga"

実行結果

${strA}_fuga
hoge_fuga