PowerShell New-ItemとForceで空のファイルを作成する

環境
PowerShell 5.1.22621.963
Windows 10 Pro 64bit

書式
New-Item ファイル名 -type file -Force
空のファイルを作成するには、「New-Item」で「-type file」を指定します。
作成するファイルが既に存在する場合は、上書きする場合は「-Force」を指定します。

操作方法
「c:\study\」に「123.txt」という空のファイルを作成します。
PS C:\Windows\system32> New-Item c:\study\123.txt -type file -Force

実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
PS C:\Windows\system32> New-Item c:\study\123.txt -type file -Force
ディレクトリ: C:\study
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2023/05/06 10:08 0 123.txt
PS C:\Windows\system32> New-Item c:\study\123.txt -type file -Force ディレクトリ: C:\study Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 2023/05/06 10:08 0 123.txt
PS C:\Windows\system32> New-Item c:\study\123.txt -type file -Force


    ディレクトリ: C:\study


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----        2023/05/06     10:08              0 123.txt

 

PowerShell

Posted by arkgame