samedi 23 juin 2012

How to get tags or serial numbers with Powershell



MERCREDI 20 JUIN 2012

How to get  tags or serial numbers with Powershell

Here is a script that gets all serial number of machines (witch are not turned off) on a lan

idée : 
We start with the first ip
we ping it
if ping ok,
we do an nslooup to get the name of the machine
and we include the scrip to get the tag.


here is the script :

$i = 1

do {

if( (Test-Connection 192.168.0.$i -Quiet -count 1)) {
            write-host "Ping OK" -ForegroundColor DarkGreen
            $status = $True
            nslookup 192.168.0.$i

            Get-WmiObject Win32_SystemEnclosure -ComputerName  192.168.0.$i   | Select SerialNumber
            write-host **********************************
        
         
         }
         else {
           
            <#
            nslookup 192.168.0.$i

            write-host "Ping failed - host "$host "not found" -ForegroundColor red
            $status = $False
           
            #>
             write-host "Ping failed - host " 192.168.0.$i  "not found" -ForegroundColor red
             write-host ********************************** 
}

$i++



}
while ($i -le 254) 

Aucun commentaire: