Thứ Năm, 21 tháng 10, 2021

How To Iterate The Content Of A Text File In Powershell

  • Use Foreach
$files = Get-Content -Path D:\PS-Tutorial\file-with-numbers.txt
ForEach ($file in $files) {
  New-Item -Name $file -Path "D:\PS-Tutorial\ForEachEx" -ItemType "directory" | Out-Null } 
}
  • Use ForEach-Object
$files = Get-Content -Path D:\PS-Tutorial\file-with-numbers.txt
$files | ForEach-Object {
   New-Item -Name $_ -Path "D:\PS-Tutorial\ForEach-ObjectEx" -ItemType "directory" | Out-Null 
}
$files = Get-Content -Path D:\PS-Tutorial\file-with-numbers.txt
$files.ForEach( {
   New-Item -Name $_ -Path "D:\PS-Tutorial\ForEachMethodEx" -ItemType "directory" | Out-Null 
} )

 

Share This!


Không có nhận xét nào:

Đăng nhận xét