PowerShellで10個のファイルを生成するコードを試してみましたが、
ファイル名の先頭に番号を付加しようとするとエラーとなってしまいます。
1_item.txt、2_item.txtと10_item.txtと作成されると思ったが、エラーとなってしまう。
Poweshell
11..10 | ForEach-Object {New-Item -Path $_item.txt}
エラー内容
PowerShell
1New-Item : Cannot bind argument to parameter 'Path' because it is null. 2At line:1 char:40 3+ 1..10 | ForEach-Object {New-Item -Path $_item.txt} 4+ ~~~~~~~~~~ 5+ CategoryInfo : InvalidData: (:) [New-Item], ParameterBindingValidationException 6+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.NewItemCommand 7
一方、ファイル名の後ろにはエラーとならずに番号が付加されたファイルが生成できています。
item1_.txt、item2_.txtとitem10.txtまで作成される。
PowerShell
11..10 | ForEach-Object {New-Item -Path item$_.txt}
いったい何が悪いのでしょうか?
以下、インストールしたPwerShellのバージョンです。
PowerShell
1PS C:\work\Powershelldir> $PSVersionTable 2 3Name Value 4---- ----- 5PSVersion 6.2.0-preview.3 6PSEdition Core 7GitCommitId 6.2.0-preview.3 8OS Microsoft Windows 10.0.17134 9Platform Win32NT 10PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} 11PSRemotingProtocolVersion 2.3 12SerializationVersion 1.1.0.1 13WSManStackVersion 3.0
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。