I am currently working on a powershell application using windows forms inside powershell. Building the forms is simple enough and I am familiar, however I have an issue that some commands that work in powershell seem to not work when putting it into my form. For example I am attempting to list the Network IP of a computer as the text of a label. The code is:
$IPAddress = Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object {$_.Ipaddress.length -gt 1}
$netIP = New-Object System.Windows.Forms.Label
$netIP.Text = "Network IP: $IPAddress.ipaddress[0]"
$netIP.Location = New-Object System.Drawing.Point(0,45)
$netIP.AutoSize = $true
$mainForm.Controls.Add($netIP)
Namely these work perfectly outside the form:
$IPAddress = Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object {$_.Ipaddress.length -gt 1}
Write-Host "Network IP:" $IPAddress.ipaddress[0]
The command itself works perfectly in Powershell but when I put it in the form as the label text it gives me the output of:
\\computername\root\cimv2:Win32_NetworkAdapterConfiguration.Index=11.ipaddress(0)
Any thoughts on this would be greatly appreciated.
Thanks for any assistance
-Tairros