Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Extract PSObject NotePropertys into variables

$
0
0

Say I have a PSObject that has a varying number of NoteProperty fields that I need to split into individual string variables.

Here is a sample:

PS C:\> $myPSObj

IIS Site       External IP (F5 VIP)            Host Header                                               
--------------      --------------------            -----------------                                               
website.com      10.10.10.10      www.website.com...                      

nextweb.com     10.10.10.11     www.nextweb.com...

My goal is to do something like this:

$myStrings=@()

foreach ($site in $myPSObj){

$myStrings+="The website "+$site.'IIS Site'+ "has an external IP of "+$site.'External IP (F5 VIP)'+" and contains the host headers "+$site.'Host Header'

}

How can I acheive this if I do not know the what the names of the NoteProperties are ahead of time?

I know I can get the names using this:

$names = ($rdptest |gm -MemberType *Property).Name

but I'm not sure how I can integrate that into the foreach.

Any help is much appreciated!



Viewing all articles
Browse latest Browse all 21975

Trending Articles