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.
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 “cannot convert System.Object[] to System.String” even though get-Member (or the method gettype()) says that it IS ALREADY a System.String…
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:
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:
$oldipaddress[0]
-> 1
(first digit of 10.0.0.101)
it says the same value (the first digit of the IP) as after the re-assignment of the variable:
$OldIPAddress = "$OldIPAddress"
$OldIPAddress[0]
-> 1
so how can you determine if the variable is an array?
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.
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.
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.
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.
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.