PoshCode Archive  Artifact [d671db5fbb]

Artifact d671db5fbbc87a510651b723951fea27698782598faf323db291bbb1e101f686:

  • File Get-IPFromAD.ps1 — part of check-in [0ea7928242] at 2018-06-10 13:52:25 on branch trunk — Check All Active Directory Computers For IP Address (user: unknown size: 868)

# encoding: ascii
# api: powershell
# title: 
# description: Check All Active Directory Computers For IP Address
# version: 0.1
# type: function
# license: CC0
# function: Get-IPFromAD
# x-poshcode-id: 5248
# x-archived: 2014-06-25T05:19:29
#
#
function Get-IPFromAD {
	
    import-module ActiveDirectory
    $PATH = "C:\Reports\$(get-date -UFormat "%Y%m%d%A-%H%M")-AD_DNS_Report.csv"
    get-adcomputer -filter * | % { 
        
        $computer = $_.Name
        $record = @{"Computer" = $computer}

        try {
            $ip = [System.Net.Dns]::GetHostEntry($computer).AddressList.IPAddressToString
            $record.Add("IPAddress", $ip)        
        }

        catch {
            $record.Add("IPAddress", "NULL")
        }
            New-Object PSObject -property $record
       
       } | export-csv -path $PATH

}