powershell 操作前的Hyper-V主机数据捕获

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell 操作前的Hyper-V主机数据捕获相关的知识,希望对你有一定的参考价值。

#---------------------------------------------------------
$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
}

以上是关于powershell 操作前的Hyper-V主机数据捕获的主要内容,如果未能解决你的问题,请参考以下文章

powershell 从其注册表中获取Hyper-V VM的VM主机

Windows Server 2012 R2 Hyper-V PowerShell远端安装Hyper-V

Hyper-V 2016 系列教程40 使用 PowerShell 实现虚拟机自动化和管理虚拟机

Docker随笔:Hyper-V PowerShell Module is not available报错解决方法

监控Hyper-V 宿主机上的虚拟机数量

powershell 仅启用Hyper-V PowerShell