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で特定ディレクトリのファイル内文字列を置換する

Get-ChildItem . | ForEach-Object {Get-Content -Encoding utf8 $_ | ForEach-Object {$_ -creplace &#039 …

no image

PowerShellで文字列の置換をする方法

確認環境 PSVersion 5.1.18362.1171 文字列の置換 -replace 以下のように置換したい文字列のあとに-replaceとカンマの前に置き換えたい文字列を、カンマの後に置き換え …

no image

PowerShellでプロセスの停止を待機するコマンドレットWait-Processの使い方

こんにちは、今日はPowerShellでプロセスの停止を待機するコマンドレットWait-Processの使い方についてまとめていきます。 確認環境 PSVersion 5.1.18362.1110 W …

no image

PowerShellでホストプログラムを取得するコマンドレットGet-Hostの使い方

こんにちは、今日はPowerShellでホストプログラムを取得するコマンドレットGet-Hostの使い方についてまとめていきます。 確認環境 PSVersion 5.1.18362.1110 Get- …

no image

PowerShellでユーザーの入力と出力結果を記録してテキストに出力するStart-Transcriptの使い方

記録を開始する Start-Transcript Start-Transcriptコマンドレットで記録を開始します。出力ファイルを指定しない場合、自動でユーザーの Documents 以下にテキストが …