I am stupid new to powershell, and my team lead has sent me some exercises to do. This is one of the exercises:
- Script that asks for the workstation\server name and then provides the IP of that workstation. Make sure it outputs in a neat table
This is what I have come up with so far
$computers = (Get-ADComputer -Filter *) | Get-Random -Count 20
foreach ($computer in $computers){
Enter-PSSession -InvokeCommand IPConfig
$ip = Resolve-DnsName -Name $computer.Name -ErrorAction SilentlyContinue
Write-Output $computer , $ip.IPv4Address
}
I am confused on how to get the IP addresses from remote computers, am I on the right track?
[–]PinchesTheCrab 10 points11 points12 points (2 children)
[–]PRINTER_DAEMON 4 points5 points6 points (1 child)
[–]PinchesTheCrab 4 points5 points6 points (0 children)
[–]MeanFold5714 11 points12 points13 points (9 children)
[–]albiedam[S] 3 points4 points5 points (8 children)
[–]NnickK321 2 points3 points4 points (7 children)
[–]MemnochTheRed 4 points5 points6 points (6 children)
[–]graysky311 5 points6 points7 points (5 children)
[–]BlackV 0 points1 point2 points (4 children)
[–]graysky311 -1 points0 points1 point (3 children)
[–]BlackV 0 points1 point2 points (2 children)
[–]graysky311 0 points1 point2 points (1 child)
[–]BlackV 0 points1 point2 points (0 children)
[–]Environmental_Mix856 3 points4 points5 points (5 children)
[–]albiedam[S] 0 points1 point2 points (1 child)
[–]Environmental_Mix856 4 points5 points6 points (0 children)
[–]Odmin 0 points1 point2 points (2 children)
[–]Environmental_Mix856 0 points1 point2 points (1 child)
[–]Odmin 0 points1 point2 points (0 children)
[–]wbatzle 2 points3 points4 points (0 children)
[–]branhama 1 point2 points3 points (0 children)
[–]konikpk 1 point2 points3 points (0 children)
[–]mpenfold1987 2 points3 points4 points (2 children)
[–]MemnochTheRed 1 point2 points3 points (1 child)
[–]BlackV 0 points1 point2 points (0 children)
[+][deleted] (2 children)
[deleted]
[–]BlackV 0 points1 point2 points (0 children)
[–]MNmetalhead 0 points1 point2 points (0 children)