HI Guys,
I've a script that takes a list of VM's and collects various bits of information on them
The script works very well but, I still need to load the data into Excel and manipulate it manually before the data can be used with other scripts. I'm wondering if there's a way to eliminate this manual work ?
Specifically, for each VM, the script determines the number of hard disks and returns the following for each disk
In the Hash table, I can be left with dozens of rows for all the VM's and each VM could have multiple entries for each of the above 3 items.
E.g. HDD1 DataStore, HDD2 DataStore, HDD3 Datastore ... ... ...
What I want to do is take all the "HDDx DataStore" entries from the hash table and return just the unique entries so that I can then go off and get specific info on these specific Datastores, number of VM's, names of VM's etc...
I've tried using Wild Cards, Where Statements, etc... I can't get it to work.
Attached is the fill script that I 'm using.
Below is the closest that I've come to getting this to work but, it's still not adding all the DataStore information in the second hash table $dsReport
Within the Attached script, I've $dsReport lines highlighted
$report=@()
$dsReport=@()
...
...
$hdd = 1
$Computer | Get-HardDisk | foreach {
$GeneralProp.Add("HDD$($hdd) Name",$_.Name)
$GeneralProp.Add("HDD$($hdd) Datastore",$_.FileName.split(" ")[0].TrimStart("[").TrimEnd("]"))
$GeneralProp.Add("HDD$($hdd) Path",$_.FileName.split(" ")[1].TrimStart("[").TrimEnd("]"))
$GeneralProp.Add("HDD$($hdd) Capacity",$_.CapacityGb)
$dsProp=@{Name = $_.FileName.split(" ")[0].TrimStart("[").TrimEnd("]")}
$hdd++
}
...
...
$dsReport | select Name -Unique
Any/All help is appreciated
Thanks
Something like this?
get-vm | foreach {
$disks = @()
$_ | get-harddisk | foreach {
$dsname = $_.Filename.split(" ")[0].TrimStart("[").TrimEnd("]")
$disks += $_ | Add-Member -MemberType NoteProperty -Name DatastoreName -Value $dsname -PassThru
}
$disks | Group-Object -Property DatastoreName
}
Something like this?
get-vm | foreach {
$disks = @()
$_ | get-harddisk | foreach {
$dsname = $_.Filename.split(" ")[0].TrimStart("[").TrimEnd("]")
$disks += $_ | Add-Member -MemberType NoteProperty -Name DatastoreName -Value $dsname -PassThru
}
$disks | Group-Object -Property DatastoreName
}
Thanks Zik, that worked perfectly.
I was missing two items from my efforts
Thanks again