<#
.SYNOPSIS
get-gateway
.DESCRIPTION
This script pulls the gateway settings for computers listed in a CSV file.
.EXAMPLE
get-gateway.ps1 -pcs c:\bin\computers.csv
#>
[cmdletbinding()]
# Require path parameter to CSV file
param([Parameter(Mandatory=$true)]$pcs)
function get-gateway{
#Create an empty array
$results = @()
[array] $computers = Import-Csv $pcs
foreach ($i in $computers){
$nics = Get-WmiObject -ComputerName $i.pcname Win32_NetworkAdapterConfiguration |
Where-Object {$_.IPEnabled -eq "True" -and $_.DefaultIPGateway -ne $null}
ForEach($nic in $nics){
$results += $i.pcname + "<-->" + $nic.DefaultIPGateway}
}
#Export results into a text file
Get-Date | Out-File -Append c:\bin\computergateway.txt
$results | Out-File -Append c:\bin\computergateway.txt
}
get-gateway
No comments:
Post a Comment