Powershell Script: Get-ChildItem
Demonstrating the use of the PS cmdlet: Get-ChildItem

Disciple of Jesus, husband, and father.
Job: Full Stack Developer/Architect Interests: Technology and football
Search for a command to run...
Demonstrating the use of the PS cmdlet: Get-ChildItem

Disciple of Jesus, husband, and father.
Job: Full Stack Developer/Architect Interests: Technology and football
No comments yet. Be the first to comment.
This series is where I will be publishing all other tech articles that can't be categorized
In this article, I want to demonstrate the use of the PowerShell cmdlet: Get-ChildItem.
Let's consider this scenario.
Imagine you need to get the list of file names in a folder to a CSV or flat file. Sounds simple, right? Yes, it is, but what if the folder contains 100’s of files? Well, it’s not that simple.
And what if you don’t want the entire filename? Instead, read the characters before a ‘-‘ and pad some spaces or zero’s on each line. Well, PowerShell comes to our rescue in this case.
$files = (Get-ChildItem -Path \192.168.0.10\ToBeLoadedPics -Filter *.jpg)
$result = @();
for($i=0;$i -lt $files.Count;$i++)
{
$file = $files[$i]
$row = $file.Name.Substring(0,$file.Name.IndexOf("-"));
$outline = "00${row} ,${file}".PadRight(94,' ');
$result += $outline;
}
$result | Out-File \192.168.0.10\Output\LoadedPics.csv