I'm currently trying to use PowerShell to create a function that would give me a list of computers and their diskdrive serial numbers. I need it to display in a hash table with 2 columns.
Here is my function so far. I thought that by creating objects and specifying what member to get and display, that it would create the array that I needed, but when I run the function, I get an output but the Disks column still outputs as an array of objects. I need to turn it into a hashtable. Do I need to merge the two in order to do that?
function Get-DiskInventory {
[string[]]$computers = $env:COMPUTERNAME
foreach ($computer in $computers) {
$system = Get-WmiObject win32_ComputerSystem -Computername $computer
$disks = Get-WmiObject win32_DiskDrive -ComputerName $computer
$computerobj = New-Object -TypeName PSCustomObject
$computerobj | Add-Member -MemberType NoteProperty -Name Name -Value $computer
#Gather Disk Info, collect mulitple disks
$diskinfo = @()
foreach ($disk in $disks) {
$diskobj = New-Object -TypeName PSObject
$diskobj | Add-Member -MemberType NoteProperty -Name SerialNumber -Value $disk.SerialNumber
$diskinfo += $diskobj
}
#add disk collector to computer obj
$computerobj | Add-Member -MemberType NoteProperty -Name Disks -Value $diskinfo
$computerobj
} #End foreach computer
} #End Fucntion
Get-DiskInventory