Author Posts

March 27, 2015 at 1:28 am


I'm a MCT and giving Powershell Classes. I'm teaching the Course 10961 for a while now, but I never figured something out, occuring in the LAB from Module 10 (Putting it all together):

in the Lab you get the "Old Ipaddress" via get-DHCPv4ServerLease and the MACAddress of that Server Core instance.

$OldIPaddress = get-DHCPv4Serverlease -Computername LON-DC1 -ScopeID | where-object {$_.ClientID -eq "WA-TH-EV-ER-00"} | select -expandproperty IPAddress | select -expandproperty IPAddressToString

as a result you get the IP adress saved in the Variable $OldIPAddress.... if you pipe it in get-member you see its a [System.String]

but nonetheless, you have to "place the $OLDIpaddress variable in double quotationmarks, and assign the resulting string to $OLDIpaddress. This will convert the IP Address to a string Object" (Page 10-9 from the offical MOC Course-Book, Exercise 2, Task2, step number 10)

Alright it works... but I don't get why you need to do this.... because it is already a string!

If you do not do this, Setting the trustedHostsList will fail with [i]"cannot convert System.Object[] to System.String"[/i] even though get-Member (or the method gettype()) says that it IS ALREADY a System.String...

Set-Item WSMAN:\localhost\Client\TrustedHosts -Value $OldIPaddress

That really bothers me and I cannot explain this to my Students....

Can anyone help me?

Sorry for bad english... I'm German 😉

March 27, 2015 at 5:18 am

It sounds to me more like it is an array of strings than a string. Get-Member is probably just describing the contents of the array.

What happens if you do $OLDIPAddress[0] with it?

March 27, 2015 at 6:12 am

TrustedHosts is a comma-separated string value. If you've got an array of IP addresses and want to assign them all to trusted hosts, you can do something like this:

Set-Item WSMAN:\localhost\Client\TrustedHosts -Value ($OldIPAddress -join ',')

March 27, 2015 at 11:42 am

The result of

$OldIPaddress = get-DHCPv4Serverlease -Computername LON-DC1 -ScopeID | where-object {$_.ClientID -eq "WA-TH-EV-ER-00"} | select -expandproperty IPAddress | select -expandproperty IPAddressToString

Is a string array, not a string. Using it in double quotes collapses it into a simple string.

March 28, 2015 at 10:08 am


thanks for your responses.
I thought of this (beeing an array of strings) too, but I didn't find a way to show it to my students that $OldIPaddress is an array, before I put it in Quotationmarks...

because if I type:


-> [i]1[/i]
(first digit of

it says the same value (the first digit of the IP) as after the re-assignment of the variable:

$OldIPAddress = "$OldIPAddress"

-> [i]1[/i]

so how can you determine if the variable is an array?

thanks again for your quick reactions.

March 28, 2015 at 10:25 am

Couple of options:


Get-Member -InputObject $OldIPAddress

March 30, 2015 at 10:33 pm

Hey Dave,

thanks for your answer, but I am aware of this technique. Nevertheless this does NOT give me a possibility to distinguishe between an array of strings with one Object and an non-array variable with one Object, in this special case!

PS C:\WINDOWS> $OldIPaddress.gettype()

[i]IsPublic IsSerial Name BaseType
——– ——– —- ——–
True True String System.Object[/i]

and after:

$OldIPaddress = "$OldIPaddress"

it is the stays the same result:

PS C:\WINDOWS> $OldIPaddress.gettype()

[i]IsPublic IsSerial Name BaseType
——– ——– —- ——–
True True String System.Object[/i]

same here with:

 Get-Member -InputObject $OldIPaddress

I appreciate your help, but I have no solution so far. 🙂


March 31, 2015 at 3:54 am

If $OldIPAddress.GetType() is telling you it's a string, then you should be able to pass it to WSMan as-is. The problem only comes up when the pipeline starting with "get-DHCPv4Serverlease" returns multiple results, instead of a single record. When that happens, $OldIPAddress will be an Object[] array containing two or more String objects.

If you want to reliably demonstrate this, then you'll need to make sure you can duplicate the conditions that cause Get-DHCPv4ServerLease to return multiple results.

April 1, 2015 at 5:17 am

Thanks for your seggestion.

But I can reproduce the case reliably without Problems. And look:

so I don't understand whats going on here. 🙂

I appreciate your help and hope we find a solution to this weird stuff 😉

April 1, 2015 at 5:19 am

There's a big difference between $OldIPAddress.GetType() and (Get-Member -InputObject $OldIPAddress).GetType() . I'm not sure where the latter one came from, in your screenshot.

April 1, 2015 at 5:51 am

Sorry, I was accidentially attaching the wrong Picture. I was not sure if I was posting the Picture correctly, so I wanted to to upload the same pic which I also embedded/posted it the text. I will delete the attachment.

April 1, 2015 at 5:54 am

Whoa... that is incredibly weird. I'll see if I can reproduce it.

April 1, 2015 at 7:06 am

Whoa… that is incredibly weird. I'll see if I can reproduce it.

happy to see that other People find it strange too and I not went crazy 🙂

April 2, 2015 at 6:35 pm

I can recreate this like this:

$OldIPAddress = [ipaddress] "" | select -ExpandProperty IPAddressToString
Set-Item WSMan:\localhost\Client\TrustedHosts -Value $OldIPAddress

IPAddressToString is a ScriptProperty added by the extended type system. Turns out you'll get the same error if you extend an object yourself:

$Test = "*" | Add-Member -NotePropertyName TestProperty -NotePropertyValue test -PassThru
Set-Item WSMan:\localhost\Client\TrustedHosts -Value $Test  # Fails
Set-Item WSMan:\localhost\Client\TrustedHosts -Value $Test.psobject.BaseObject  # Succeeds

It looks like the WSManConfigProvider really doesn't like extended objects.

April 9, 2015 at 12:18 am

Wow thanks, you made my day. That seems to be the Problem. It is indeed the WSMANConfig-provider. I think this may be a useful information for the publisher of the Powershell-Course MOC 10961. I see to give them a feedback, with this information.

Thanks alot you guys for helping me out. 🙂