Let’s say I want to change the host description on several PCs at once, and I have a script like this:
Set-HostNameDescription -ComputerName myHost -Description "This is my PC"
Now, I have a list of hosts and their descriptions in a text file, my question is, how should I format that text file to properly pipe the values? like this:
Assuming your ComputerName parameter is of type [string], and accepts ValueFromPipeline, and you’ve properly implemented a PROCESS{} block, then your text file would be one name per line.
See “Learn PowerShell Toolmaking in a Month of Lunches” for a walkthrough on pretty much exactly this, if you need.
Ah - I should point out that you couldn’t pipe the Description AND ComputerName from a text file like that.
What you could do is rig both parameters to accept ValueFromPipelineByPropertyName (Mandatory has no bearing here), and instead of a text file, use a CSV file having a ComputerName column and a Description column. Import that using Import-CSV, and pipe it to your command. Again, assuming you’ve properly implemented a PROCESS{} block in the command.
Ah, I see, yes, the script has PROCESS{} and all that, it works fine but since there are several parameters to be inputted I wasn’t sure about the type of file, I knew a comma delimited wouldn’t work.
Regarding “Learn PowerShell Toolmaking in a Month of Lunches”, dude, I’ve been devouring all those videos and others, I’m hooked.