Skip to content

Instantly share code, notes, and snippets.

@uemuraj
Created November 5, 2022 04:30
Show Gist options
  • Save uemuraj/d9b28402942af73f34cdca345ae30676 to your computer and use it in GitHub Desktop.
Save uemuraj/d9b28402942af73f34cdca345ae30676 to your computer and use it in GitHub Desktop.
動作中の仮想マシンを適当に確認したい時に
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
@uemuraj
Copy link
Author

uemuraj commented Nov 5, 2022

管理者のパスワードが、どの仮想マシンでも同じなら、あらかじめ ID とパスワードを保存しておけば良い。

PS> Get-Credential | Export-CliXml -Path .\ServerCred.xml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment