Monday, February 3, 2014

Poor Man's Hardware Inventory - Powershell through logon script

We are in the middle of migrating a domain to ours and I was working on a plan to move all of the PC's over. I wanted to make sure that I was able to capture all of the existing hardware/OS configs without staying up till 2am and grab them manually... if they were online:)
I came up with this powershell script that will run on logon and write back to a specified location. Then I could gather them as people logged on/connected.
$name = (Get-Item env:\Computername).Value
$filepath = "\\SERVER\DIRECTORY"

function inventory {
# MotherBoard: Win32_BaseBoard
$manuf = Get-WmiObject Win32_ComputerSystem -ComputerName $name
# Hard-Disk
$hd = Get-WmiObject win32_diskDrive -ComputerName $name | ForEach-Object {[math]::round($_.size / 1GB)}
# Memory
$mem = Get-WmiObject Win32_ComputerSystem -ComputerName $name | ForEach-Object {[math]::round($_.TotalPhysicalMemory / 1GB)}
# Processor 
$cpu = Get-WmiObject Win32_Processor -ComputerName $name
#OS Architecture
$OS = Get-WmiObject Win32_OperatingSystem -ComputerName $name
## System enclosure 
$enc = Get-WmiObject Win32_SystemEnclosure -ComputerName $name
$type = $enc.chassistypes
$chassis = Switch ($type)
    {
        "1" {"Other"}
        "2" {"Virtual Machine"}
        "3" {"Desktop"}
        "4" {"Low Profile Desktop"}
        "5" {"Pizza Box"}
        "6" {"Mini Tower"}
        "7" {"Tower"}
        "8" {"Portable"}
        "9" {"Laptop"}
        "10" {"Notebook"}
        "11" {"Handheld"}
        "12" {"Docking Station"}
        "13" {"All-in-One"}
        "14" {"Sub-Notebook"}
        "15" {"Space Saving"}
        "16" {"Lunch Box"}
        "17" {"Main System Chassis"}
        "18" {"Expansion Chassis"}
        "19" {"Sub-Chassis"}
        "20" {"Bus Expansion Chassis"}
        "21" {"Peripheral Chassis"}
        "22" {"Storage Chassis"}
        "23" {"Rack Mount Chassis"}
        "24" {"Sealed-Case PC"}
        Default {"Unknown"}
     }

##Excract Object Data
$obj = New-Object psobject
$obj | Add-Member noteproperty Manufacturer $manuf.Manufacturer
$obj | Add-Member noteproperty Model $manuf.Model
$obj | Add-Member noteproperty CPU $cpu.Name
$obj | add-member noteproperty RAM $mem
$obj | add-member noteproperty HD $hd
$obj | Add-Member noteproperty Type $chassis
$obj | Add-Member noteproperty OS $OS.Caption
$obj | Add-Member noteproperty Arch $OS.OSArchitecture
Write-Output $obj
}

##Run function and export to csv
inventory | format-table
inventory | Export-Csv -NoTypeInformation $filepath\$name.csv

Remote Mailboxes - Hybrid Config - Missing

The Remote Mailbox exists on the On Prem Exchange server and linked to the Office 365 mailbox. Without one of these for each Office 365 mail...