- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello
I have created the below script, my issue is that the result like this
and I would like to have the output in this order:
- Name
- Type
- path
- FreeSpacePercent
- FreeSpaceGB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There doesn't seem to be any code in your post.
In any case, if you want to keep the properties in the order you define them in the code, one way of doing that is to use the [ordered]@ construct
New-Object -TypeName PSObject -Property ([ordered]@{
Prop1 = 'value'
Prop2 = 'value'
Prop3 = 'value'
})
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry missed to add the script ![]()
# Get all datastores in the vCenter Datacenters
$datastores = Get-Datastore -Location (Get-Datacenter)
# Create an empty array to hold the datastore information
$datastoreInfo = @()
# Loop through each datastore
foreach ($datastore in $datastores) {
# Get the datastore type, host or network path, available space in GB and %
$type = $datastore.ExtensionData.Info.GetType().Name
$path = $datastore.ExtensionData.Info.Url
$freeSpaceGB = "{0:N2}" -f ($datastore.FreeSpaceGB)
if ($datastore.CapacityGB -eq 0) {
$freeSpacePercent = "N/A"
} else {
$freeSpacePercent = "{0:N2}" -f ($datastore.FreeSpaceGB / $datastore.CapacityGB * 100)
}
# Add the information to the array
$datastoreInfo += New-Object PSObject -Property @{
Name = $datastore.Name
Type = $type
Path = $path
FreeSpaceGB = $freeSpaceGB
FreeSpacePercent = $freeSpacePercent
}
}
$PreContent = "<style>
table {
border-collapse: collapse;
with: 100%;
}
th, td {
padding: 8px;
text-align: left;
border-bottom: 1px solid #ddd;
}
tr:hover {
background-color: coral;
}
</style>"
$PostContent = "<br>"
$datastoreInfo | ConvertTo-Html -Fragment -PreContent $PreContent -PostContent $PostContent | Out-File "datastore_info.html"
$datastoreInfo | Export-Csv -Path .\datastore_info.csv -Append -NoTypeInformation -Force
# Disconnect from vCenter server
Disconnect-VIServer * -Force -Confirm:$false
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Like I said earlier, use the [ordered] construct.
# Add the information to the array
$datastoreInfo += New-Object PSObject -Property ([ordered]@{
Name = $datastore.Name
Type = $type
Path = $path
FreeSpaceGB = $freeSpaceGB
FreeSpacePercent = $freeSpacePercent
})
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference