Created
November 5, 2022 04:30
-
-
Save uemuraj/d9b28402942af73f34cdca345ae30676 to your computer and use it in GitHub Desktop.
動作中の仮想マシンを適当に確認したい時に
This file contains hidden or 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
function Get-VMList { | |
$credential = Import-CliXml -Path .\ServerCred.xml | |
$informations = @() | |
foreach ($vm in (Get-VM | Where-Object State -eq Running)) { | |
$informations += Invoke-Command -VMName $vm.Name -Credential $credential -ScriptBlock { | |
$info = Get-ComputerInfo | Select-Object -Property @{Name = "OS"; Expression = { $_.WindowsProductName + ' ' + $_.OSDisplayVersion } }, @{Name = "Name"; Expression = { $_.CsName } } | |
$info | Add-Member -MemberType NoteProperty -Name IP -Value (Get-NetIPAddress -AddressFamily IPv4 | Where-Object InterfaceAlias -notlike 'Loopback*' | ForEach-Object { $_.IPAddress }) | |
Write-Output $info | |
} | |
} | |
$informations | Select-Object -Property * -ExcludeProperty PSComputerName, RunspaceId | Write-Output | |
} | |
Get-VMList |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
管理者のパスワードが、どの仮想マシンでも同じなら、あらかじめ ID とパスワードを保存しておけば良い。