Hi All
The following is a report that i am trying to create. The report is empty for Raw Disk Mappings: and Independent Disk Setting: i know there are 4 drives for the vm that i am quering but cannot figuer out how to do the foreach to put it in the reprot. Any help would be appreciated. Thank you. The following is the code followed by an output report.
# This is to gather data
Clear-Host
$VC = Read-Host "Enter Virtual Center the VM is In?"
Connect-viserver -Server $VC
Clear-Host
$VM = Read-host "Enter Windows Virtual Server to Query?"
Clear-Host
Write-Host " Please wait gathering Data for Report!"
$VMR = Get-VM -Name $VM
$VMD = Get-VM -Name $VM | Get-HardDisk
$NIC = (Get-VM -Name $VM | Get-NetworkAdapter).ExtensionData.AddressType
$OS = Get-Wmiobject Win32_Operatingsystem -ComputerName $VM
$VMB = (Get-Vm -Name $VM | Get-ScsiController).BusSharingMode
$CPA = (Get-VM -Name $VM | Get-View).Config.CpuAffinity
$FLP = (Get-VM -Name $VM | Get-FloppyDrive).FloppyImagePath
$VMS = Get-VM -Name $VM | Get-Snapshot
# Creating Report
"Virtual Machine Name: " + $VM | Out-File c:\MigReport.txt
"Raw Disk Mappings: " + $VMD.DiskType | Out-File c:\MigReport.txt -Append
"VM Notes From DataCenter: " + $VMR.Notes | Out-File c:\MigReport.txt -Append
"Static MAC Address: " + $NIC | Out-File c:\MigReport.txt -Append
"OS Version and Service pack: " + $OS.Caption + $OS.CSDVersion | Out-File c:\MigReport.txt -Append
"SCSI Bus Sharing Status: " + $VMB | Out-File c:\MigReport.txt -Append
"CPU Pinning Status: " + $CPA | Out-File c:\MigReport.txt -Append
"Floppy Drive Connection: " + $FLP | Out-File c:\MigReport.txt -Append
"Virtual Machine SnapShots: " + $VMS | Out-File c:\MigReport.txt -Append
"Independent Disk Setting: " + $VMD.Persistence | Out-File c:\MigReport.txt -Append
II c:\MigReport.txt
Virtual Machine Name: ServerA
Raw Disk Mappings:
VM Notes From DataCenter: Virtual Machine created by PlateSpin Portability Suite 8.0.0.5954 on 2/6/2010 12:01:49 AM
Static MAC Address:
OS Version and Service pack: Microsoft(R) Windows(R) Server 2003, Standard EditionService Pack 2
SCSI Bus Sharing Status: NoSharing
CPU Pinning Status:
Floppy Drive Connection:
Virtual Machine SnapShots:
Independent Disk Setting:
VMWare report
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: VMWare report
$OUTPUT_FILE = ($Env:USERPROFILE + '\Desktop\MigReport.txt')
Clear-Host
#If function was using parameters set the defaults there, here we are going to set to ""
# later if -eq "" we will read-host
$VC = "" #feel free to set this if its very common, again id create parameters if i were you
if (!$VC) { #Handles Null, Nonexist, or Empty
$VC = Read-Host "Enter Virtual Center the VM is In?"
Clear-Host
}
Connect-viserver -Server $VC
# if we were smart we would put error checking so the script STOPS if connection fails!
#if VMs -eq "" we will read-host
$VMs = ""
if (!$VMs) { #Handles Null, Nonexist, or Empty
$VMs = Read-Host "Enter Virtual Center the VM is In?"
Clear-Host
}
#FUTURE GOOD IDEA:
# whether in the read-host or now, if test-path of $VMs exist, we will assume a CRLF seperated file of VMs
# otherwise we will assume a single VM guest name
#if (test-path $VMs) {
# VMs = import file into variable
#}
# For now, we will assume One VM. I use the Variable STRINGVM because this is not a VMWare object, just a string.
$StringVM = $VMs
# turn this into a parameter, or find a way to detect it, if you want localization
$LANGUAGE = "ENG"
$VM_LABEL_ENG = "Virtual Machine Name"
$VM_DISK_MAPPING_LABEL_ENG = "Raw Mapping"
$VM_DISK_IDEPENDENT_LABEL_ENG = "Independent Disk"
$VM_NOTES_LABEL_ENG = "VM Notes From DataCenter"
$VM_MAC_LABEL_ENG = "Static MAC Address"
$WMI_OS_LABEL_ENG = "OS Version and Service Pack"
$VM_SCSIBUS_LABEL_ENG = "SCSI Bus Sharing Status"
$VM_AFFINITYSTATUS_LABEL_ENG = "CPU Pinning Status"
$VM_FLOPPY_LABEL_ENG = "Floppy Drive Connection"
$VM_SNAPSHOT_LABEL_ENG = "Virtual Machine SnapShots"
$VM_LABEL_CUR = Invoke-Expression ('$VM_LABEL_'+$LANGUAGE)
$VM_DISK_MAPPING_LABEL_CUR = Invoke-Expression ('$VM_DISK_MAPPING_LABEL_'+$LANGUAGE)
$VM_DISK_IDEPENDENT_LABEL_CUR = Invoke-Expression ('$VM_DISK_IDEPENDENT_LABEL_'+$LANGUAGE)
$VM_NOTES_LABEL_CUR = Invoke-Expression ('$VM_NOTES_LABEL_'+$LANGUAGE)
$VM_MAC_LABEL_CUR = Invoke-Expression ('$VM_MAC_LABEL_'+$LANGUAGE)
$WMI_OS_LABEL_CUR = Invoke-Expression ('$WMI_OS_LABEL_'+$LANGUAGE)
$VM_SCSIBUS_LABEL_CUR = Invoke-Expression ('$VM_SCSIBUS_LABEL_'+$LANGUAGE)
$VM_AFFINITYSTATUS_LABEL_CUR = Invoke-Expression ('$VM_AFFINITYSTATUS_LABEL_'+$LANGUAGE)
$VM_FLOPPY_LABEL_CUR = Invoke-Expression ('$VM_FLOPPY_LABEL_'+$LANGUAGE)
$VM_SNAPSHOT_LABEL_CUR = Invoke-Expression ('$VM_SNAPSHOT_LABEL_'+$LANGUAGE)
# This is to gather data
Write-Host " Please wait gathering Data for Report!"
#GET VM OBJECTs
$VM = Get-VM -Name $StringVM #by only calling this once we are not constantly re-querying Vsphere
$VM_VIEW = Get-View -VIObject $VM
#GET NOTES FROM VM OBJECT
$VM_Notes = $VM.Notes
#GET HDD FROM VM OBJECT
$VM_Disks = Get-HardDisk -VM $VM |`
select-object Name,`
@{"N"=$VM_DISK_MAPPING_LABEL_CUR;"E"={$_.Disktype.tostring()}},`
@{"N"=$VM_DISK_IDEPENDENT_LABEL_CUR;"E"={$_.Persistence.tostring()}}
$VM_NICs = Get-NetworkAdapter -Vm $VM |`
select-object Name,Type,NetworkName,MacAddress,`
@{"N"=$VM_MAC_LABEL_CUR;"E"={$_.ExtensionData.AddressType}}
$WMI_OS = Get-Wmiobject Win32_Operatingsystem -ComputerName $StringVM -Property caption,csdversion
$WMI_OS_Caption = $WMI_OS.Caption
$WMI_OS_ServicePack = $WMI_OS.CSDVersion
$VM_SCSI = (get-ScsiController -VM $VM).BusSharingMode
$VM_CPU_Affinity = $VM_View.config.CpuAffinity
$VM_FLP = (Get-FloppyDrive -VM $vm).FloppyImagePath #cannot verify this, none of my vms have floppies
$VM_SNAPSHOT = Get-Snapshot -VM $VM #i cannot help write a good looking report because none of my VMs have snapshot right now
#however, i would do a select-object and only select the columns that are interesting, i tend to change all values to strings
#when writing a report so that you can later export to html or csv, etc.
#if i wanted this for a pipeline i would create a psobject to stuff it into
#I changed the order of your report to put things that have a possibility of being multi-row on bottom
($VM_LABEL_CUR + ': ' + $StringVM) | out-file $Output_file
($VM_NOTES_LABEL_CUR + ': ' + $VM_Notes) | out-file $Output_file -append
($WMI_OS_LABEL_CUR + ': ' + $WMI_OS_Caption + ' ' + $WMI_OS_ServicePack) | out-file $Output_file -append
($VM_AFFINITYSTATUS_LABEL_CUR + ': ' + $VM_CPU_Affinity) | out-file $Output_file -append
($VM_SCSIBUS_LABEL_CUR + ': ' + $VM_SCSI) | out-file $Output_file -append
'HDD Info: ' | out-file $Output_file -append
$VM_Disks | out-file $Output_file -append
($VM_FLOPPY_LABEL_CUR + ': ' + $VM_FLP) | out-file $Output_file -append
'NIC Info: ' | out-file $Output_file -append
$VM_NICs | format-table | out-file $Output_file -append
($VM_SNAPSHOT_LABEL_CUR + ': ' + $VM_SNAPSHOT) | out-file $Output_file -append
Clear-Host
#If function was using parameters set the defaults there, here we are going to set to ""
# later if -eq "" we will read-host
$VC = "" #feel free to set this if its very common, again id create parameters if i were you
if (!$VC) { #Handles Null, Nonexist, or Empty
$VC = Read-Host "Enter Virtual Center the VM is In?"
Clear-Host
}
Connect-viserver -Server $VC
# if we were smart we would put error checking so the script STOPS if connection fails!
#if VMs -eq "" we will read-host
$VMs = ""
if (!$VMs) { #Handles Null, Nonexist, or Empty
$VMs = Read-Host "Enter Virtual Center the VM is In?"
Clear-Host
}
#FUTURE GOOD IDEA:
# whether in the read-host or now, if test-path of $VMs exist, we will assume a CRLF seperated file of VMs
# otherwise we will assume a single VM guest name
#if (test-path $VMs) {
# VMs = import file into variable
#}
# For now, we will assume One VM. I use the Variable STRINGVM because this is not a VMWare object, just a string.
$StringVM = $VMs
# turn this into a parameter, or find a way to detect it, if you want localization
$LANGUAGE = "ENG"
$VM_LABEL_ENG = "Virtual Machine Name"
$VM_DISK_MAPPING_LABEL_ENG = "Raw Mapping"
$VM_DISK_IDEPENDENT_LABEL_ENG = "Independent Disk"
$VM_NOTES_LABEL_ENG = "VM Notes From DataCenter"
$VM_MAC_LABEL_ENG = "Static MAC Address"
$WMI_OS_LABEL_ENG = "OS Version and Service Pack"
$VM_SCSIBUS_LABEL_ENG = "SCSI Bus Sharing Status"
$VM_AFFINITYSTATUS_LABEL_ENG = "CPU Pinning Status"
$VM_FLOPPY_LABEL_ENG = "Floppy Drive Connection"
$VM_SNAPSHOT_LABEL_ENG = "Virtual Machine SnapShots"
$VM_LABEL_CUR = Invoke-Expression ('$VM_LABEL_'+$LANGUAGE)
$VM_DISK_MAPPING_LABEL_CUR = Invoke-Expression ('$VM_DISK_MAPPING_LABEL_'+$LANGUAGE)
$VM_DISK_IDEPENDENT_LABEL_CUR = Invoke-Expression ('$VM_DISK_IDEPENDENT_LABEL_'+$LANGUAGE)
$VM_NOTES_LABEL_CUR = Invoke-Expression ('$VM_NOTES_LABEL_'+$LANGUAGE)
$VM_MAC_LABEL_CUR = Invoke-Expression ('$VM_MAC_LABEL_'+$LANGUAGE)
$WMI_OS_LABEL_CUR = Invoke-Expression ('$WMI_OS_LABEL_'+$LANGUAGE)
$VM_SCSIBUS_LABEL_CUR = Invoke-Expression ('$VM_SCSIBUS_LABEL_'+$LANGUAGE)
$VM_AFFINITYSTATUS_LABEL_CUR = Invoke-Expression ('$VM_AFFINITYSTATUS_LABEL_'+$LANGUAGE)
$VM_FLOPPY_LABEL_CUR = Invoke-Expression ('$VM_FLOPPY_LABEL_'+$LANGUAGE)
$VM_SNAPSHOT_LABEL_CUR = Invoke-Expression ('$VM_SNAPSHOT_LABEL_'+$LANGUAGE)
# This is to gather data
Write-Host " Please wait gathering Data for Report!"
#GET VM OBJECTs
$VM = Get-VM -Name $StringVM #by only calling this once we are not constantly re-querying Vsphere
$VM_VIEW = Get-View -VIObject $VM
#GET NOTES FROM VM OBJECT
$VM_Notes = $VM.Notes
#GET HDD FROM VM OBJECT
$VM_Disks = Get-HardDisk -VM $VM |`
select-object Name,`
@{"N"=$VM_DISK_MAPPING_LABEL_CUR;"E"={$_.Disktype.tostring()}},`
@{"N"=$VM_DISK_IDEPENDENT_LABEL_CUR;"E"={$_.Persistence.tostring()}}
$VM_NICs = Get-NetworkAdapter -Vm $VM |`
select-object Name,Type,NetworkName,MacAddress,`
@{"N"=$VM_MAC_LABEL_CUR;"E"={$_.ExtensionData.AddressType}}
$WMI_OS = Get-Wmiobject Win32_Operatingsystem -ComputerName $StringVM -Property caption,csdversion
$WMI_OS_Caption = $WMI_OS.Caption
$WMI_OS_ServicePack = $WMI_OS.CSDVersion
$VM_SCSI = (get-ScsiController -VM $VM).BusSharingMode
$VM_CPU_Affinity = $VM_View.config.CpuAffinity
$VM_FLP = (Get-FloppyDrive -VM $vm).FloppyImagePath #cannot verify this, none of my vms have floppies
$VM_SNAPSHOT = Get-Snapshot -VM $VM #i cannot help write a good looking report because none of my VMs have snapshot right now
#however, i would do a select-object and only select the columns that are interesting, i tend to change all values to strings
#when writing a report so that you can later export to html or csv, etc.
#if i wanted this for a pipeline i would create a psobject to stuff it into
#I changed the order of your report to put things that have a possibility of being multi-row on bottom
($VM_LABEL_CUR + ': ' + $StringVM) | out-file $Output_file
($VM_NOTES_LABEL_CUR + ': ' + $VM_Notes) | out-file $Output_file -append
($WMI_OS_LABEL_CUR + ': ' + $WMI_OS_Caption + ' ' + $WMI_OS_ServicePack) | out-file $Output_file -append
($VM_AFFINITYSTATUS_LABEL_CUR + ': ' + $VM_CPU_Affinity) | out-file $Output_file -append
($VM_SCSIBUS_LABEL_CUR + ': ' + $VM_SCSI) | out-file $Output_file -append
'HDD Info: ' | out-file $Output_file -append
$VM_Disks | out-file $Output_file -append
($VM_FLOPPY_LABEL_CUR + ': ' + $VM_FLP) | out-file $Output_file -append
'NIC Info: ' | out-file $Output_file -append
$VM_NICs | format-table | out-file $Output_file -append
($VM_SNAPSHOT_LABEL_CUR + ': ' + $VM_SNAPSHOT) | out-file $Output_file -append
- jrremillard
- Posts: 58
- Last visit: Sun Aug 08, 2021 7:42 am
- Shane.Saviers
- Posts: 17
- Last visit: Mon Oct 24, 2022 2:35 pm
Re: VMWare report
galaara98 - very useful comments that helped me change up one of my VM scripts.
Thanks!
Thanks!
- Shane Saviers