Link to home
Start Free TrialLog in
Avatar of alienvoice
alienvoiceFlag for Australia

asked on

Powershell script - IP of local PC

I am attempt to write a powershell script that will extract the IP address of a local PC it is being run on.

So far I have written this:

$strComputerID = "."
$Ipinfo = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "IPEnabled=TRUE and DHCPEnabled=TRUE" -comp $strComputerID
# get-member -inputobject $Ipinfo ----------- I am using this line to identify the type of info available
get-member -name IPAddress $IPinfo

What am I missing. I understand $Ipinfo is an array, but I can't extract individual information from it like IPAddress or DefaultIPGateway and so on.

Ideas?
ASKER CERTIFIED SOLUTION
Avatar of theruck
theruck
Flag of Slovakia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of alienvoice

ASKER

Thanks everyone, suggestions were appreciated. Most of the suggestions worked, I have gone with code as listed below:

$strComputerID = "."
$Ipinfo = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "IPEnabled=TRUE and DHCPEnabled=TRUE" -comp $strComputerID
$IPinfo.IPAddress

Reason behind this is, it will allow me to modify the input if needed at a later date and it will run a check to verify the IP is DHCP enabled, (which is important for the situation it will be used in).