1

I have a startup script that captures an IP address out of the registry using the following code:

$icaaddr=(Get-ItemProperty "HKLM:\SOFTWARE\Wow6432Node\Citrix\XTEConfig" -Name "DefaultICAAddress")
[Net.IPAddress]$icaaddr=$icaaddr.DefaultICAAddress

Later in that script that IP is used for different things and it is added to the "Message" output as such

$message+="ICA address found to be: $icaaddr `n"

However today on one server instead of an IP the following was captured.

ICA address found to be: @{DefaultICAAddress=; PSPath=Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Citrix\XTEConfig; PSParentPath=Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Citrix; PSChildName=XTEConfig; PSDrive=HKLM; PSProvider=Microsoft.PowerShell.Core\Registry}

So my questions are 2

  1. What would cause such output
  2. How could I test for this 'state'

Long story short is when the ouptut is like that I need to have the server rebooted. How can I test the $icaaddr variable contains a valid IP address

brittonv
  • 713
  • 3
  • 7
  • 12

1 Answers1

0

You need to change this line:

$icaaddr=(Get-ItemProperty "HKLM:\SOFTWARE\Wow6432Node\Citrix\XTEConfig" -Name "DefaultICAAddress")

to:

$icaaddr=(Get-ItemProperty "HKLM:\SOFTWARE\Wow6432Node\Citrix\XTEConfig" -Name "DefaultICAAddress").DefaultICAAddress

or (this way is more readable IMO):

$icaaddr = Get-ItemProperty "HKLM:\SOFTWARE\Wow6432Node\Citrix\XTEConfig" `
    -Name "DefaultICAAddress" | Select-Object -ExpandProperty "DefaultICAAddress"

because Get-ItemProperty returns an object and you need a single property.

Note, however, that in your example DefaultICAAddress seems to be empty and trying to cast it to [Net.IPAddress] will likely throw an exception. To avoid this you should check if the value is a valid IP address.

Community
  • 1
  • 1
Alexander Obersht
  • 3,215
  • 2
  • 22
  • 26
  • sorry for the delay but I don't think you understand my problem. This script works fine as is. Reboot hundreds of servers with it. However on one server this one day I saw the above. Rebooted the same server again and it worked fine. Just trying to figure out what went wrong. – brittonv Jul 14 '14 at 20:14