I am a beginner in Powershell and as my internship project, I have to write a script for hardware/software inventory of the systems on the network.
The issue which I am not able to resolve is that instead of having the names of all the computers in the text file computer.txt as mentioned by you, I have a text file having the IP Addresses of all the systems on the network.
In most of the scripts that I have come across, the code is
"
$name = (Get-Item env:\Computername).Value
"
Now, when I am tweaking my script accordingly, the $name only returns the value of the system I am working on (localhost).
Please help me with this. How can I use IP Addresses to gather information of the systems.
PS - I am attaching a small code of how I have been proceeding below. And the text file containing the ip addresses
$arrComputers = get-Content -Path "D:\Work\computerlist.txt"
foreach ($strComputer in $arrComputers)
{
$name=(get-item env:\computername).value
$ipadd=([system.net.dns]::gethostaddresses($strComputer))
$hostname=([system.net.dns]::gethostentry($ip)).hostname
$network = Get-WmiObject -class Win32_NetworkAdapterConfiguration -ComputerName $name -Authentication PacketPrivacy -Impersonation Impersonate
foreach ($objItem in $network)
{
Write-host "======== info starts here ======================= "
Write-host "IP Address:" $ipadd
Write-host "Host Name: " $hostname
Write-host "MAC Address : " ($objItem).MACAddress
Write-host "DNS Domain : " ($objItem).DNSDomain
Write-host "======== info ends here ======================="
}
} computerlist.txt file contain addresses as follows:
10.208.35.7
10.208.35.9
10.208.35.10
10.208.35.12
10.208.35.13
10.208.35.16
10.208.35.17
10.208.35.25
10.208.35.36
10.208.35.37
Please provide me with a solution
Thanks.