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

メールアドレスが公開されることはありません。

関連記事

no image

PowerShellでWebリクエストを実行するコマンドレットInvoke-WebRequestの使い方

こんにちは、今日はPowerShellでWebリクエストを実行するコマンドレットInvoke-WebRequestの使い方についてまとめていきます。 確認環境 PSVersion 5.1.18362. …

no image

PowerShellで文字列が特定の文字列から始まっているか判定する

確認環境 PSVersion 5.1.18362.1110 特定の文字から始まっているか判定 stringのStartsWith関数に文字列を渡すと、その文字列で始まっているか判定することができます。 …

no image

PowerShellでロード済のアセンブリ一覧を取得する

以下のように現在のアプリケーション ドメインを取得し、そのドメインで読み込まれているアセンブリをGetAssemblies関数で取得します。 PS C:\Users\santerabyte> & …

no image

PowerShellで実行ポリシーを設定するコマンドレットSet-ExecutionPolicyの使い方

こんにちは、今日はPowerShellで実行ポリシーを設定するコマンドレットSet-ExecutionPolicyの使い方についてまとめていきます。 確認環境 PSVersion 5.1.18362. …

no image

PowerShellでファイル名から拡張子を取得する

こんにちは、今日はPowerShellでファイル名から拡張子を取得する方法についてまとめていきます。 確認環境 PSVersion 5.1.18362.1110 ファイル名から拡張子を取得する Get …