I have a simple script that reads the folder names and outputs them into a text file. I realized I got a lot more output then I wanted, so I used the select-item cmdlet to select just the name property from the hashtable. The problem is that there is still all the white space that the data I omitted would have normally filled, not helping my problem since the white space will destroy my script.
I have tried some [regex] commands to strip out the whitespace with (/S+) but I don't really know it that well I was using some code trying to tweak from an example someone helped me with. The topic name is the same as the title here and it is on this site too. Anyone that can help me I would appreciate it!
Basically, I cant figure out how to output the names of folders into a simple text file with ZERO whitespace (1 line per folder name).
$accFolder = Read-Host "Enter the account folder container....: "
$dataArray = Get-ChildItem "D:\influxcyst\$accFolder" | select-object name
$dataArray
$dataArray | Out-File $HOME\desktop\$accFolder.txt
$newArray = get-content $HOME\desktop\$accFolder.txt
#[regex]$regex = "\s(\S+)\s"
#[regex]::matches($newArray,$regex) | foreach-object {$_.groups[1].value}
Try this one:
Get-ChildItem C:\Source\Path | ForEach-Object { $_.Name } > C:\Output\File.txt
Related resources:
You can get just the names with the -Name switch:
$accFolder = Read-Host "Enter the account folder container....: "
Get-ChildItem -Name "D:\influxcyst\$accFolder" | Out-File $HOME\desktop\$accFolder.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With