Hi everyone, trying to get some guidance on a script i’m working on. I’m trying to calculate the size of folder by adding everything inside the folder, and i’m trying to do this for a list of remote machines, which means each folder path and server name is different
I have a CSV with three columns the heading for each of the columns are ServerName, FolderName, FolderPath. So far when i run the script I’m able to get the information I want but since its using Write-Host i cant out it to a file.
You never really need write-host for anything other than write colorized text to the screen or certain formatting needs.
Output to the screen is the default. If you find yourself using write-Host or any of its aliases, stop, an rethink what you are doing.
If it is a fully automated process, where a user is not at the screen the writing to the screen is really moot, since you can use -Verbose to write additional stuff to the screen without using write-Host, or just use Start/Stop-Transcript to capture stuff.
If you are ever planning to output to a file, the that eliminates Write-Host for any associated data, since Write-Host will empty the buffer, thus nothing to send down the pipeline / stream.
You can just use any of the other data redirect methods or Write-Output, Out-File, or Export-CSv, etc., to get your file.
So, tweaking what you have here, maybe this is more prudent for you
[quote quote=127579]What does the csv look like? Yes, I would use select-object or [pscustomobject] to make the object properties, then pipe to export-csv.
Are these ‘|’ really in the CSV file as the separator / delimiter, or did you just type this in this post?
Remember the ‘|’ has special meaning in PowerShell.
If that is the case, then on your import, you have deal with that, any spaces, line feeds etc.
You don’t show any code that you are addressing that at all. So… stepping through this …