Gathering buslogic SCSI hardware and virtual machine operating system

Posted by Julian on Server Fault See other posts from Server Fault or by Julian
Published on 2013-10-18T18:10:58Z Indexed on 2013/10/18 21:58 UTC
Read the original article Hit count: 280

Filed under:
|
|
|

I'm trying to use Powershell to get SCSI hardware from several virtual servers and get the operating system of each specific server. I've managed to get the specific SCSI hardware that I want to find with my code, however I'm unable to figure out how to properly get the operating system of each of the servers. Also, I'm trying to send all the data that I find into a csv log file, however I'm unsure of how you can make a powershell script create multiple columns.

Here is my code (almost works but something's wrong):

$log = "C:\Users\me\Documents\Scripts\ScsiLog.csv"
Get-VM | Foreach-Object {
    $vm = $_
        Get-ScsiController -VM $vm | Where-Object { $_.Type -eq "VirtualBusLogic" } | Foreach-Object {
            get-VMGuest -VM $vm } | Foreach-Object{
        Write-output $vm.Guest.VmName  >> $log
            }
    }

I don't receive any errors when I run this code however whenever I run it I'm only getting the name of the servers and not the OS. Also I'm not sure what I need to do to make the OS appear in a different column from the name of the server in the csv log that I'm creating.

What do I need to change in my code to get the OS version of each virtual machine and output it in a different column in my csv log file?

EDIT: Here's a more in depth look at things I've tried that have all failed:

Get-VM | Foreach-Object {
    $vm = $_    
    $svm = Get-ScsiController -VM $vm | Where-Object { $_.Type -eq "VirtualBusLogic" } 
    Foreach-Object {get-VMGuest -VM $svm } | Foreach-Object{Write-output $svm >> $log}
    }

#Get-VM | Foreach-Object {
#   $vm = $_
#       Get-ScsiController -VM $vm | Where-Object { $_.Type -eq "VirtualBusLogic"} #| write-host $vm
#       | Foreach-Object {
#       
#       #get-VMGuest -VM $_ |
#       #write-host $vm
#           #get-VMGuest -VM $vm } | Foreach-Object{
#       #write-output $vm.VmName >> $log
#       #write-output $vm.guest.VmName, get-VmGuest -VM $vm >> $log NO GOOD
#
#       Write-host $vm.Guest.VmName #+ get-vmGuest -vm $VM >> $log
#
#
#       }
#   }

I'm not sure why get-VmGuest fails though. I'm getting the scsi hardware, filtering the hardware to only get buslogic, and then wanting to get the operating system of just the filtered VMs. I don't see where my code fails though.

© Server Fault or respective owner

Related posts about vmware-esxi

Related posts about powershell