From f07ee249e6510db79d05685bc7d718e088bb5d72 Mon Sep 17 00:00:00 2001 From: Sergiy Ivanov <32060944+seyo-IV@users.noreply.github.com> Date: Wed, 19 Aug 2020 07:27:51 +0200 Subject: [PATCH] Add files via upload --- WPF-VMWareReport.ps1 | 5186 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 5186 insertions(+) create mode 100644 WPF-VMWareReport.ps1 diff --git a/WPF-VMWareReport.ps1 b/WPF-VMWareReport.ps1 new file mode 100644 index 0000000..0ae15dd --- /dev/null +++ b/WPF-VMWareReport.ps1 @@ -0,0 +1,5186 @@ +##Modules +if(Get-Module -ListAvailable -Name ImportExcel){ + # + } +else{ + +$Title = "Info" +$Info = "Install ImportExcel?" + +$Options = [System.Management.Automation.Host.ChoiceDescription[]] @("&Yes", "&No") +[int]$DefaultChoice = 0 +$Opt = $host.UI.PromptForChoice($Title , $Info, $Options, $DefaultChoice) + +switch($Opt) +{ +0 { + $check = $true + Install-Module -Name ImportExcel -Scope CurrentUser -Confirm:$false +} + +1 { + $check = $true + exit +} +} +if($check -ne $true){exit} + +try{Import-Module ImportExcel}catch{System.Windows.Forms.MessageBox]::Show('ImportExcel Could not be imported.', 'Error', 'Ok', 'Error'); exit} + + } +if(Get-Module -ListAvailable -Name ImportExcel){ + + }else{exit} + +## Functions +Function Select-File { + Add-Type -AssemblyName System.Windows.Forms + $SafeFileDialog=New-Object System.Windows.Forms.SaveFileDialog + $SafeFileDialog.filter = "Excel Files | *.xlsx" + $SafeFileDialog.Title = "Choose a save location." + if($SafeFileDialog.ShowDialog() -eq 'Ok'){ + + [System.Windows.Forms.MessageBox]::Show('File is selected.', 'Info', 'Ok', 'Information') + return $SafeFileDialog.FileName + } +} + +Function Get-VMFolder { + if($global:defaultviserver -eq $null){ + [System.Windows.Forms.MessageBox]::Show('Connect to VIServer first.', 'Error', 'Ok', 'Error') + } + else{ + $Folder = Get-Folder | Sort-Object | Get-Unique + $Folder_CB.Items.Clear() + $Folder_CB.Items.Add("All") + foreach($F in $Folder){ + $Folder_CB.Items.Add($F.Name) + } + } +} + +Function Get-VMReport { +if($File[1] -ne $null -and $global:defaultviserver -ne $null){ +$report = @() +if($Folder_CB.Text -eq "All"){ + $VMs = Get-VM +} +else { + $VMs = Get-Folder $Folder_CB.Text | Get-VM +} + $ProgressBar.Maximum = $VMs.count +foreach($vm in $VMs.Name) + { + $VMData = Get-VM $vm + $VMIP = $VMData.guest.IPAddress[0] + $VMIP = [IPAddress]$VMIP + $data = New-Object PSCustomObject -Property @{ + Name = $VMData.Name; + State = $VMData.PowerState + OS = $VMData.ExtensionData.Guest.GuestFullName; + IPv4 = $VMIP; + Cores = $VMData.NumCpu; + RAM = ("$([math]::Round($VMData.MemoryMB)) MB"); + ProvisionedSpace = ("$([math]::Round($VMData.ProvisionedSpaceGB)) GB"); + UsedSpace = ("$([math]::Round($VMData.UsedSpaceGB)) GB"); + } + $report += $data + $ProgressBar.Value += 1 + } + $xlfile = [string]$File[1] + $report | select-Object Name, State, OS, IPv4, Cores, RAM, ProvisionedSpace, UsedSpace | Export-Excel $xlfile -AutoSize -StartRow 1 -TableName VMWare +} +elseif($File[1] -eq $null -and $global:defaultviserver -ne $null){ + [System.Windows.Forms.MessageBox]::Show('CHoose file first!', 'Error', 'Ok', 'Error') +} +elseif($File[1] -ne $null -and $global:defaultviserver -eq $null){ + [System.Windows.Forms.MessageBox]::Show('Connect to VIServer first!', 'Error', 'Ok', 'Error') +} +} +Function Connect-VMVIServer { +#-------------------------------------------------------------# +#----Initial Declarations-------------------------------------# +#-------------------------------------------------------------# + +Add-Type -AssemblyName PresentationCore, PresentationFramework + +$Xaml2 = @" + + + + + + + + + + + + + + + + + + + + + + + + + + #FF000000 + #FF333333 + #FF3E3E3E + #FF505050 + #FF696969 + #FF818181 + #FF9B9B9B + #FFB1B1B1 + #FFD0D0D0 + #FFE0E0E0 + #FFF1F1F1 + #FFffffff + #FFDCEDF3 + #FF94D7F3 + #FF3BB7EB + #FF16A9E7 + #FF2788B1 + #FF19759B + #FF1A5F7C + + + #FFd3404b + #FFc62d36 + + + #00FFFFFF + #33FFFFFF + #66FFFFFF + #99FFFFFF + #CCFFFFFF + + + #00000000 + #33000000 + #66000000 + #99000000 + #CC000000 + + + #FF6E7E16 + #FFa4ba29 + #FFfdbd48 + #FFF7AA1B + #FFff888b + #FFff6a6f + #FF9e73c1 + #FF714199 + #FFf79036 + #FFBC5900 + #FF69299D + #FF371356 + #FF48892d + #FF285017 + #FFDC8F00 + #FFCA4E52 + + + #E5E7E7E7 + + + #33818181 + + + + #FF1487B8 + #FF106A92 + #FF1797CE + #FF137BA8 + #FF3EA9D7 + #FF2894C1 + #FF65BBE0 + #FF42ABD9 + #FF8BCCE9 + #FF67BDE2 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +