Created
July 17, 2023 23:08
-
-
Save joeypiccola/1dcb482471d2dadcd01ba014b2c88323 to your computer and use it in GitHub Desktop.
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
# gets a list of all vms | |
$vms = Get-VM | |
# creates an empty array | |
$vmArray = @() | |
# loops through each vm | |
foreach ($vm in $vms) { | |
# creates a custom object | |
$vmObj = [PSCustomObject]@{ | |
CPU = $vm.NumCpu | |
Memory = $vm.MemoryGB | |
Name = $vm.Name | |
Status = $vm.PowerState | |
} | |
# adds the object to the array | |
$vmArray += $vmObj | |
} | |
# converts the array to json | |
$json = $vmArray | ConvertTo-Json | |
# writes the json to a file | |
$json | Out-File -FilePath C:\temp\vm.json |
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
[ | |
{ | |
"CPU": 1, | |
"Memory": 0.125, | |
"Name": "vCLS-c845d6b6-22b6-4de1-97b8-8c308a3436af", | |
"Status": 1 | |
}, | |
{ | |
"CPU": 2, | |
"Memory": 12.0, | |
"Name": "vcsa7", | |
"Status": 1 | |
}, | |
{ | |
"CPU": 4, | |
"Memory": 16.0, | |
"Name": "control-3.piccola.us", | |
"Status": 1 | |
}, | |
{ | |
"CPU": 4, | |
"Memory": 16.0, | |
"Name": "control-1.piccola.us", | |
"Status": 1 | |
}, | |
{ | |
"CPU": 4, | |
"Memory": 16.0, | |
"Name": "control-5.piccola.us", | |
"Status": 1 | |
}, | |
{ | |
"CPU": 4, | |
"Memory": 16.0, | |
"Name": "control-4.piccola.us", | |
"Status": 1 | |
}, | |
{ | |
"CPU": 4, | |
"Memory": 16.0, | |
"Name": "control-2.piccola.us", | |
"Status": 1 | |
}, | |
{ | |
"CPU": 1, | |
"Memory": 4.0, | |
"Name": "openvpn", | |
"Status": 0 | |
}, | |
{ | |
"CPU": 4, | |
"Memory": 6.0, | |
"Name": "app01", | |
"Status": 1 | |
}, | |
{ | |
"CPU": 4, | |
"Memory": 4.0, | |
"Name": "app02", | |
"Status": 1 | |
}, | |
{ | |
"CPU": 2, | |
"Memory": 10.0, | |
"Name": "vcsa67", | |
"Status": 0 | |
}, | |
{ | |
"CPU": 4, | |
"Memory": 12.0, | |
"Name": "dockerlin", | |
"Status": 1 | |
}, | |
{ | |
"CPU": 2, | |
"Memory": 4.0, | |
"Name": "ca01", | |
"Status": 0 | |
}, | |
{ | |
"CPU": 2, | |
"Memory": 4.0, | |
"Name": "ca02", | |
"Status": 1 | |
}, | |
{ | |
"CPU": 2, | |
"Memory": 2.0, | |
"Name": "dc03", | |
"Status": 1 | |
}, | |
{ | |
"CPU": 2, | |
"Memory": 6.0, | |
"Name": "puppet", | |
"Status": 0 | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment