none
Finding env:\computername through IP address of a remote computer on the network RRS feed

  • Question

  • 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.





    • Edited by YellowDoor Tuesday, June 10, 2014 10:28 AM
    Tuesday, June 10, 2014 10:26 AM

Answers

All replies

  • What is this line in your script doing?

    $hostname=([system.net.dns]::gethostentry($ip)).hostname  


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

    Tuesday, June 10, 2014 10:56 AM
    Moderator
  • Looks like you made a typo in variable

    $hostname=([system.net.dns]::gethostentry($ipadd)).hostname 

    Change $ip to $ipadd

    $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($ipadd)).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 =======================" } }


    Regards Chen V [MCTS SharePoint 2010]

    Tuesday, June 10, 2014 11:34 AM
  • This is how to do this in PowerShell.

    Get-Content D:\Work\computerlist.txt |
         ForEach-Object{
             Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $_
         } |
           Select IPAddress, DNSHostName, MACAddress,DNSDomain |
           Format-List


    ¯\_(ツ)_/¯

    Tuesday, June 10, 2014 12:10 PM
  • yea it was a typo ..BUt thats not an issue.

    the problem is, i get this error when i try to gather inventory information like information of OS, Processor etc.

    I get these two errors

    Get-WmiObject : Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
    At line:11 char:5
    + gwmi <<<<  -class Win32_NetworkAdapterConfiguration -computername $str -Authentication PacketPrivacy -Impersonation Impersonate -filt
    er "IpEnabled=True" |select DNSHostName, MACAddress | FT -AutoSize  
        + CategoryInfo          : NotSpecified: (:) [Get-WmiObject], UnauthorizedAccessException
        + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

    and

    Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
    At line:11 char:5
    + gwmi <<<<  -class Win32_NetworkAdapterConfiguration -computername $str -Authentication PacketPrivacy -Impersonation Impersonate -filt
    er "IpEnabled=True" |select DNSHostName, MACAddress | FT -AutoSize  
        + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], COMException
        + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

    PLease help me out

    Wednesday, June 11, 2014 5:22 AM
  • Hi,

    Check the firewall and make sure you have admin rights.


    Don't retire TechNet! - (Don't give up yet - 12,950+ strong and growing)

    • Marked as answer by YellowDoor Wednesday, June 11, 2014 11:48 AM
    Wednesday, June 11, 2014 5:40 AM
  • Thank you. Will try do that
    Wednesday, June 11, 2014 11:48 AM