Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

PowerShell – Get IPv4 Machine IP

Posted on November 12, 2015March 10, 2016 By David Kittell

Approach 1

$ip=get-WmiObject Win32_NetworkAdapterConfiguration|Where {$_.Ipaddress.length -gt 1} 
$serverIP = $ip.ipaddress[0]

Approach 2

$computername = $env:COMPUTERNAME
#Test-Connection $computername -count 1 | select Address,Ipv4Address
Test-Connection $computername -count 1 | select @{Name="Computer Name";Expression={$_.Address}},@{Name="IPv4 Address";Expression={$_.Ipv4Address}}

Approach 3 – More Details

$colItems = Get-WmiObject Win32_NetworkAdapterConfiguration -Namespace "root\CIMV2" | where{$_.IPEnabled -eq "True"}

clear

Write-Host "# --------------------------------------"
Write-Host "# Local IP address information"
Write-Host "# --------------------------------------"
foreach($objItem in $colItems) {
    Write-Host "Adapter:" $objItem.Description 
    Write-Host " DNS Domain:" $objItem.DNSDomain
    Write-Host " Hostname:" $objItem.PSComputerName
    Write-Host " IPv4 Address:" $objItem.IPAddress[0]
    Write-Host " IPv6 Address:" $objItem.IPAddress[1]
    Write-Host " " 
}
Originally Posted on November 12, 2015
Last Updated on March 10, 2016
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code PowerShell IPv4Machine IP Addres

Post navigation

Previous post
Next post

Related Posts

Oracle Clean Date Format

Posted on September 18, 2013October 26, 2015

Sometimes you have to pull a date from Oracle in a cleaner format, this is one way to achieve the format you want. // Convert the Oracle date 19000101 to 01-01-1900 public string OracleCleanDate(string strDate) { if (strDate.Length == 8) { string strYear, strMonth, strDay; strYear = strDate.Substring(0, 4); strMonth…

Read More

PowerShell – Get Text Encoding Type

Posted on June 16, 2020August 17, 2024

function Get-Encoding { param ( [Parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName)] [Alias(‘FullName’)] [string] $Path ) process { $bom = New-Object -TypeName System.Byte[](4) $file = New-Object System.IO.FileStream($Path, ‘Open’, ‘Read’) $null = $file.Read($bom,0,4) $file.Close() $file.Dispose() $enc = [Text.Encoding]::ASCII if ($bom[0] -eq 0x2b -and $bom[1] -eq 0x2f -and $bom[2] -eq 0x76) { $enc = [Text.Encoding]::UTF7 } if ($bom[0]…

Read More

Network Connection Configurations

Posted on June 25, 2013October 26, 2015

If you are on Windows Vista/7/8 you will need to create the batch file and then run it as administrator. In the examples below you will need to first know what the connection name is for your network connection(s) When you click on the start menu or Windows key on…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • PowerShell - IIS Remove Site
  • Front Page
  • SQLite - Auto-Increment / Auto Generate GUID
  • PowerShell - FTP Upload Directory With Sub-Directories

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • PowerShell - IIS Remove Site
  • SQLite - Auto-Increment / Auto Generate GUID
  • PowerShell - FTP Upload Directory With Sub-Directories
  • Raspberry Pi - Remove Default Apps
  • PowerShell - Change Windows CD/DVD Drive Letter
©2025 David Kittell | WordPress Theme by SuperbThemes