Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Creating one custom object out one .net static method and one parameter

$
0
0

Hey Guys got this code:

$Comps = Get-Content C:\comps.txt

Foreach ($i in $comps) {
Try
{
Write-Host $i
[System.Net.Dns]::GetHostAddresses("$i") | fl IPAddressToString -ErrorAction stop
}
Catch 
{
Write-Host "Computer $i is not accessible `n"
continue 
}
    }

C:\comps is just a list of computers - I'm getting there last seen IP's from our DNS records - what I would like to do however is instead of printing 

Computer Name

<Output of static method>  as two seperate lines 

I'd much rather create an object with two parameters - Name of computer, and IP address. How can I take the output of the write-host and the output of the static method and place them into one object? This would make formatting much easier and I would be able to export to csv.

Thanks guys. 


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>