3テラバイト

プログラム関連備忘録サイト。主にゲーム。

PowerShell

PowerShellでアイテムのコンテンツを設定するコマンドレットSet-Contentの使い方

投稿日:

こんにちは、今日はPowerShellでアイテムのコンテンツを設定するコマンドレットSet-Contentの使い方についてまとめていきます。

確認環境

PSVersion 5.1.18362.1110

Set-Contentの使い方

第一引数に設定するアイテムを、第二引数に設定する値を指定すると、アイテムのコンテンツの値を設定できます。

以下の例ではカレントディレクトリにある「test.txt」のコンテンツの値を「Hello World」に設定しています。

PS C:\Users\santerabyte> Set-Content .\test.txt -Value 'Hello World'

オプションを省略しない場合

PS C:\Users\santerabyte> Set-Content -Path .\test.txt -Value 'Hello World'

サンプル

PS C:\Users\santerabyte> Get-Content .\test.txt
Test Text
PS C:\Users\santerabyte> Set-Content .\test.txt 'Hello World'
PS C:\Users\santerabyte> Get-Content .\test.txt
Hello World

リンク

Set-Content (Microsoft.PowerShell.Management) – PowerShell | Microsoft Docs
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/set-content?view=powershell-7.1

-PowerShell


comment

メールアドレスが公開されることはありません。 が付いている欄は必須項目です


reCaptcha の認証期間が終了しました。ページを再読み込みしてください。

関連記事

no image

PowerShellでコマンド実行結果をテキストファイルに保存する

以下のようにパイプでOut-Fileコマンドレットに結果を渡すか、>演算子を用いて出力先のファイルを指定します。 PS C:\Users\santerabyte> Get-ChildItem | …

no image

PowerShellの論理演算子一覧

確認環境 PSVersion 5.1.18362.1110 演算子他言語の演算子説明-not!否定!!否定-and&論理積-or|論理和-xor^排他的論理和 リンク if ステートメントにつ …

no image

PowerShellで開いているウィンドウをすべて最小化する

確認環境 PSVersion 5.1.18362.1110 開いているウィンドウをすべて最小化する 以下のようにShell.ApplicationのCOMオブジェクトを生成、MinimizeAll関数 …

no image

PowerShellでテキストファイルを1行ずつ処理する

こんにちは、今日はPowerShellでテキストファイルを1行ずつ処理する方法についてまとめていきます。 確認環境 PSVersion 5.1.18362.1110 テキストファイルを1行ずつ処理する …

no image

PowerShellでコンソールに出力するコマンドレットWrite-Hostの使い方

こんにちは、今日はPowerShellでコンソールに出力するコマンドレットWrite-Hostの使い方についてまとめていきます。 確認環境 PSVersion 5.1.18362.1110 Write …