Loading Now

Powershell Infogetter

This script will help you gather info on devices in an OU. This script will lookup the devices in the OU you define and then for each it will; Test-NetworkConnection to see if the device is online, If online get the model, current user and OS Version. It will store this info in an array that you can then display or export to csv.

Fill input array

There are a couple ways to get info ready for this script. One way is to create a CSV file with one column named name and add one server name per line. We can then fill our $servers array with this command:

$servers = Import-Csv -Path "C:\Path\To\CSV.csv

The other way is to get PC names from an OU in Active Directory you can do that with this command. (make sure you have a connection to AD, see this Post)

$servers = Get-ADComputer -Filter * -SearchBase "OU=Computers,DC=Domain,DC=com"

Script:

$result = @()

foreach ($server in $servers) {
    $server = $server.name
    try {
        Test-NetConnection -ComputerName $server -ErrorAction Stop
        $model = Invoke-Command -computername $server -scriptblock {WMIC CSPRODUCT GET NAME} -ErrorAction Stop
        $username = Invoke-Command -computername $server -scriptblock {WMIC COMPUTERSYSTEM GET USERNAME} -ErrorAction Stop
        $OS = Invoke-Command -computername $server -scriptblock {WMIC OS GET VERSION} -ErrorAction Stop
        Write-Host $server "," $model "," $username "," $OS
        $result += "$server,$model,$username,$OS"
    }
    
    catch {
        Write-Host $server ",is,Off,line"
        $result += "$server,is,Off,line"
    }
}

Now we have an array of results you can display just by typing the $result and hit enter in PS. Or you can export it with this command:

$result | out-file C:\ps\output.txt

My name is Skylar Pearce, I have been working as a System Administror since 2013 as well some side consulting work. During my career I have worked with everything from Active Directory and vCenter to configuring routers and switches and phone systems, documenting and scripting my way through the whole thing. I have a Security+ certification and am currently working on my PenTest+. Throughout my career I have gained almost all of my knowledge from blogs like this. It is now time for me to pay it back. Over time I have gathered scripts and tricks over the years that I will share on this site. A lot of the posts here will be mainly reference posts, some will be full on how to’s. I am happy to go into more depth on any other topics I go over here, just make a comment on a post. I will do my best to post once a day on weekdays but as I run out of ideas it may slow down. My WordPress skills are still growing so the site will likely get better over time as I learn. You can reach me at contact@allthesystems.com or on LinkedIn