1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Powershellでワンライナー(iniファイル内の文字列置換)

Last updated at Posted at 2022-04-28

はじめに

今はバッチで色々スクリプト組んでますが、やりたいことを簡単に実現させたいので(1行で貼りつけるだけで簡単にできるので楽)

ワンライナー

IniFileReplace.ps1
# sample.ini内の文字列を今日の日付に置換
Get-Content sample.ini | ForEach-Object { $_ -replace "YYYY/MM/DD",(Get-Date).ToString("yyyy/MM/dd") } | Out-File -Encoding default sample.ini

参考サイト

※関係ないサイトもあるのですが、後で使うことあるかもなので
◆【Powershell】ファイル内の文字列を置換して上書きする方法
 https://pig-log.com/powershell-replace-overwrite/
◆PowerShell でファイル内の文字列をワンライナーで置換する
 https://qiita.com/kaku10/items/7c28fa5ebc829efe301c
◆yyyymmdd 形式の文字列で現在日付を取得する方法
 https://bayashita.com/p/entry/show/38
◆【PowerShell】前日の日時を取得しフォーマットする
 https://kharuka2016.hatenablog.com/entry/2017/02/28/201531
◆PowerShell/当日・指定日付の曜日を取得する方法
 https://win.just4fun.biz/?PowerShell/%E5%BD%93%E6%97%A5%E3%83%BB%E6%8C%87%E5%AE%9A%E6%97%A5%E4%BB%98%E3%81%AE%E6%9B%9C%E6%97%A5%E3%82%92%E5%8F%96%E5%BE%97%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95
◆Powershellでの高度な置換
 https://qiita.com/acuo/items/a4f83d886c4b8a7fcf52
◆powershellでiniファイルを扱いたい
 http://nmksb.seesaa.net/article/473354419.html
◆PowerShellで"="や":"区切りの設定ファイルを読み込む
 https://yomon.hatenablog.com/entry/2014/05/21/PowerShell%E3%81%A7%22%3D%22%E3%82%84%22%3A%22%E5%8C%BA%E5%88%87%E3%82%8A%E3%81%AE%E8%A8%AD%E5%AE%9A%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%82%92%E8%AA%AD%E3%81%BF%E8%BE%BC%E3%82%80
◆Using the ConvertFrom-String cmdlet to parse structured text
 https://powershellmagazine.com/2014/09/09/using-the-convertfrom-string-cmdlet-to-parse-structured-text/
◆Powershellで色々とJSON形式に変換する
 https://qiita.com/digitalMagicbox/items/441f692ee040a476ead3

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?