Set-StrictMode -Version Latest
Set-ExecutionPolicy remotesigned -Force
import-module activedirectory
$ComputerName = $env:ComputerName
Get-ADComputer -Filter '*' -SearchBase "OU=Computers, DC=sample,DC=com" -Properites Name | % {
$PC = $_Name
begin {}
process {
foreach ($Computer in $ComputerName) {
if(Test-Connection -ComputerName $Computer -Count 1 -TimeToLive -Quiet)
{
$Networks = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $Computer | ? {$_.IPEnabled}
foreach ($Network in $Networks) {
$IsDHCPEnabled = $false
"ComputerName" = $_.ComputerName
"IPAddress" = $_.IpAddress
"SubnetMask" = $_.IPSubnet
"DefaultGateway" = $_.DefaultIPGateway
"DNSServers" = $_.DNSServers
"MACAddress" = $_.MACAddress
"IsDHCPEnabled" = $_.false
If($Network.DHCPEnabled) {
$IsDHCPEnabled = $true
}
New-Object PSObject -Property @{
"ComputerName" = $_.ComputerName
"IPAddress" = $_.IPAddress
"Subnet" = $_.SubnetMask
"DefaultGateway" = $_.DefaultGateway
"DNSServers" = $_.DNSServers
"MACAddress" = $_.MACAddress
"IsDHCPEnabled" = $_.True
} Export-Csv c:\Scripts\DesktopIPVerified.csv -Append -Notypeinformation
}
}
}
}
end {}
}