Last active
October 18, 2017 04:26
-
-
Save techthoughts2/c00f6baf8772cb60a4a08579510515f8 to your computer and use it in GitHub Desktop.
This is a handy little snippet of code that you can run on a Hyper-V server prior to performing a maintenance action. It will capture all the critical information you might want to know about the Hyper-V server and dumps it to a text file so you can reference during and after a maintenance process.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#--------------------------------------------------------- | |
$hostname = $env:COMPUTERNAME | |
$path = "C:\logging" | |
$vms = Get-VM | |
#--------------------------------------------------------- | |
$hostname | Out-File $path\$hostname.txt -Append | |
ipconfig /all | Out-File $path\$hostname.txt -Append | |
Get-NetAdapter -ErrorAction SilentlyContinue | Out-File $path\$hostname.txt -Append | |
Get-VMSwitch -ErrorAction SilentlyContinue | Out-File $path\$hostname.txt -Append | |
Get-Cluster -ErrorAction SilentlyContinue | Out-File $path\$hostname.txt -Append | |
Get-ClusterGroup -ErrorAction SilentlyContinue | Out-File $path\$hostname.txt -Append | |
Get-ClusterResource -ErrorAction SilentlyContinue | Out-File $path\$hostname.txt -Append | |
Get-ClusterNetwork -ErrorAction SilentlyContinue | Out-File $path\$hostname.txt -Append | |
Get-Disk -ErrorAction SilentlyContinue | Out-File $path\$hostname.txt -Append | |
Get-Volume -ErrorAction SilentlyContinue | Out-File $path\$hostname.txt -Append | |
Get-WindowsFeature -ErrorAction SilentlyContinue | Where-Object {$_.installed -eq "True"} | Out-File $path\$hostname.txt -Append | |
Get-WmiObject -Class Win32_Product -ErrorAction SilentlyContinue | Out-File $path\$hostname.txt -Append | |
$vms = Get-VM -ErrorAction SilentlyContinue | |
$vms | Out-File $path\$hostname.txt -Append | |
#now get all VHD files associated with those VMs | |
foreach ($VM in $VMs ) { | |
$VM.Name | Out-File $path\$hostname.txt -Append | |
Get-VHD -VMId $VM.VMId | ` | |
Format-Table ` | |
vhdtype, ` | |
@{label = ’Size(GB)’; expression = {$_.filesize / 1gb –as [int]}}, ` | |
@{label = ’MaxSize(GB)’; expression = {$_.size / 1gb –as [int]}}, ` | |
path ` | |
-AutoSize | Out-File $path\$hostname.txt -Append | |
"------------------------------" | Out-File $path\$hostname.txt -Append | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment