引用符
ドキュメント:
特殊文字
ドキュメント:
代入する
ドキュメント:
文字列での変数の代入 | Microsoft Learn [公式]
結合する
+演算子-join: 結合演算子
文字列を + 演算子で結合する。
$greeting = "Hello, " + "World"
複数の文字列を結合演算子 -Join で結合する。
$foobar = -join "hoge", "fuga", "piyo"
デリミタを指定して文字列を結合演算子 -Join で結合する。
$greeting = "Hello", "World" -join ", "
ドキュメント:
参考:
PowerShell で文字列を結合する方法 5選 | 適材適所
文字列を連結する | Simple Sand Samples
PowerShell で文字列を連結する | Delft スタック
分割する (-Split)
ドキュメント:
参考:
ストリームに出力する
Write-HostWrite-Output
参考:
Write-Host と Write-Output の違い | iPentec
ファイルに出力する
Set-ContentAdd-ContentOut-File
ドキュメント:
Set-Content | Microsoft Learn [公式]
Add-Content | Microsoft Learn [公式]
Out-File | Microsoft Learn [公式]
参考:
Set-Content / Add-Content – ファイルへの上書きと追記方法 | Windows と暮らす
PowerShell の Out-File と Set-Content あるいは Out-File -Append と Add-Content の違い | tech.guitarrapc.cóm
リダイレクト
ドキュメント:
出力のリダイレクト | Microsoft Learn [公式]
Start-Transcript | Microsoft Learn [公式]
参考:
What’s the best way to redirect STDOUT and STDERR to a log file? – reddit
コンソールに出力する
ドキュメント:
Out-Host | Microsoft Learn [公式]
空文字を判定する
変数が空文字もしくはヌルであるかを判定するには、[String]::IsNullOrEmpty メソッドを使う。
if ([String]::IsNullOrEmpty($str)) {
Write-Host '$str is null or empty.'
}
ドキュメント:
String.IsNullOrEmpty メソッド | Microsoft Learn [公式]
参考:
文字列が空文字や NULL であるかを判定する方法 | バヤシタ
Powershell で文字列が null かどうか判定する方法 | Rainbow Engine
PowerShell で文字列などの変数の Null または空文字を確認するには | YOMON8.NET
PowerShell で変数の Null や空文字を判定する方法 | miajimyu note
文字に色を付ける
参考:
文字エンコード
ドキュメント:
文字エンコード | Microsoft Learn [公式]
参考:
Write-Host
ドキュメント:
Write-Host | Microsoft Learn [公式]
参考:
Write-Host 時に改行しない方法/途中で改行する方法 | バヤシタ
Write-Output
ドキュメント:
Write-Output | Microsoft Learn [公式]
参考:
Write-Output で複数文字を改行せずに出力する方法 | FAQ Center
Set-Content
ドキュメント:
Set-Content | Microsoft Learn [公式]
参考:
特殊文字をエスケープする
参考:
エスケープシーケンスはバッククォートを使う | IT ガイド
How to escape special characters? – Stack Overflow
What is the literal escape character? – Server Fault
escaping ampersand and plus sign – Stack Overflow