Now I learnt (I do hope that I get this right) that when passing objects via the pipeline the process block will be automatically looped for every object coming from the pipeline. Do I have this right?
However, when I use get-something -ComputerName client1, client2 etc I need to loop through the “array” of $ComputerName.
Can I determine in the Begin block if the script is used as a pipeline “target”?
Correct. When input is piped in, $Computername will only contain one item at a time. If provided on the parameter, PROCESS executes once and $ComputerName contains all items.
You don’t need to determine it, though. Just build the PROCESS block to handle both.
PROCESS {
foreach($computer in $computername) {
# use $computer
}
}
In the pipeline mode, the foreach is redundant but doesn’t add much extra time since it only has to loop once. Either way, $computer will only contain one name at a time, this way.
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
Name NoteProperty System.String Name=SomeName
So a piped Get-ADComputer -Filter {OperatingSystem -NotLike “server”} -Properties * | select Name still has something like “Name=SomeName” in it.
Doing a $myVar[-1].Name | gm will give me only the string name and not “Name=SomeName”.
What would I need to change either in the process code block or in the calling pipe command?
It was late yesterday and now I could see the ByValue and ByPropertyName!
Will check this one: Get-ADComputer -filter * | Select @{n=’computername’;e={$_.name}} | My-Function
By the way, couldn’t resist buying the book. I have watched the 2 introduction events from Jeffrey Snower and Jason Helmick and for sure this was mentioned
Many more questions for new threads but I may solve some on my own