Public/Get-ESXStorage.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 |
function Get-ESXStorage { <# .SYNOPSIS Get ESXi Storage Details .DESCRIPTION Will get iSCSI Software and Fibre Channel Adapter (HBA) details including Datastores All this can be gathered for a vSphere Cluster, Datacenter or individual ESXi host .NOTES File Name : Get-ESXStorage.ps1 Author : Edgar Sanchez - @edmsanchez13 Contributor : Ariel Sanchez - @arielsanchezmor Version : 2.4.4 .Link https://github.com/arielsanchezmora/vDocumentation .INPUTS No inputs required .OUTPUTS CSV file Excel file .PARAMETER esxi The name(s) of the vSphere ESXi Host(s) .EXAMPLE Get-ESXStorage -esxi devvm001.lab.local .PARAMETER cluster The name(s) of the vSphere Cluster(s) .EXAMPLE Get-ESXStorage -cluster production-cluster .PARAMETER datacenter The name(s) of the vSphere Virtual DataCenter(s) .EXAMPLE Get-ESXStorage -datacenter vDC001 Get-ESXInventory -datacenter "all vdc" will gather all hosts in vCenter(s). This is the default if no Parameter (-esxi, -cluster, or -datacenter) is specified. .PARAMETER ExportCSV Switch to export all data to CSV file. File is saved to the current user directory from where the script was executed. Use -folderPath parameter to specify a alternate location .EXAMPLE Get-ESXStorage -cluster production-cluster -ExportCSV .PARAMETER ExportExcel Switch to export all data to Excel file (No need to have Excel Installed). This relies on ImportExcel Module to be installed. ImportExcel Module can be installed directly from the PowerShell Gallery. See https://github.com/dfinke/ImportExcel for more information File is saved to the current user directory from where the script was executed. Use -folderPath parameter to specify an alternate location .EXAMPLE Get-ESXStorage -cluster production-cluster -ExportExcel .PARAMETER StorageAdapters Default switch to get iSCSI Software and Fibre Channel Adapter (HBA) details This is default option that will get processed if no switch parameter is provided. .EXAMPLE Get-ESXStorage -cluster production-cluster -StorageAdapters .PARAMETER Datastores Switch to get Datastores details .EXAMPLE Get-ESXStorage -cluster production-cluster -Datastores .PARAMETER folderPath Specificies an alternate folder path of where the exported file should be saved. .EXAMPLE Get-ESXStorage -cluster production-cluster -ExportExcel -folderPath C:\temp .PARAMETER PassThru Returns the object to the console .EXAMPLE Get-ESXStorage -esxi devvm001.lab.local -PassThru #> <# ----------------------------------------------------------[Declarations]---------------------------------------------------------- #> [CmdletBinding()] param ( $esxi, $cluster, $datacenter, [switch]$ExportCSV, [switch]$ExportExcel, [switch]$StorageAdapters, [switch]$Datastores, [switch]$PassThru, $folderPath ) $FibreChannelCollection = @() $iSCSICollection = @() $DatastoresCollection = @() $skipCollection = @() $vHostList = @() $date = Get-Date -format s $date = $date -replace ":", "-" $outputFile = "Storage" + $date <# ----------------------------------------------------------[Execution]---------------------------------------------------------- #> <# Query PowerCLI and vDocumentation versions if running Verbose #> if ($VerbosePreference -eq "continue") { Write-Verbose -Message ((Get-Date -Format G) + "`tPowerCLI Version:") Get-Module -Name VMware.* | Select-Object -Property Name, Version | Format-Table -AutoSize Write-Verbose -Message ((Get-Date -Format G) + "`tvDocumentation Version:") Get-Module -Name vDocumentation | Select-Object -Property Name, Version | Format-Table -AutoSize } #END if <# Check for an active connection to a VIServer #> Write-Verbose -Message ((Get-Date -Format G) + "`tValidate connection to a vSphere server") if ($Global:DefaultViServers.Count -gt 0) { Write-Host "`tConnected to $Global:DefaultViServers" -ForegroundColor Green } else { Write-Error -Message "You must be connected to a vSphere server before running this Cmdlet." break } #END if/else <# Validate if a parameter was specified (-esxi, -cluster, or -datacenter) Although all 3 can be specified, only the first is used Example: -esxi "host001" -cluster "test-cluster". -esxi is the first parameter and what will be used. #> Write-Verbose -Message ((Get-Date -Format G) + "`tValidate parameters used") if ([string]::IsNullOrWhiteSpace($esxi) -and [string]::IsNullOrWhiteSpace($cluster) -and [string]::IsNullOrWhiteSpace($datacenter)) { Write-Verbose -Message ((Get-Date -Format G) + "`tA parameter (-esxi, -cluster, -datacenter) was not specified. Will gather all hosts") $datacenter = "all vdc" } #END if <# Gather host list based on parameter used #> Write-Verbose -Message ((Get-Date -Format G) + "`tGather host list") if ([string]::IsNullOrWhiteSpace($esxi)) { Write-Verbose -Message ((Get-Date -Format G) + "`t-esxi parameter is Null or Empty") if ([string]::IsNullOrWhiteSpace($cluster)) { Write-Verbose -Message ((Get-Date -Format G) + "`t-cluster parameter is Null or Empty") if ([string]::IsNullOrWhiteSpace($datacenter)) { Write-Verbose -Message ((Get-Date -Format G) + "`t-datacenter parameter is Null or Empty") } else { Write-Verbose -Message ((Get-Date -Format G) + "`tExecuting Cmdlet using datacenter parameter") if ($datacenter -eq "all vdc") { Write-Host "`tGathering all hosts from the following vCenter(s): " $Global:DefaultViServers $vHostList = Get-VMHost | Sort-Object -Property Name } else { Write-Host "`tGathering host list from the following DataCenter(s): " (@($datacenter) -join ',') foreach ($vDCname in $datacenter) { $tempList = Get-Datacenter -Name $vDCname.Trim() -ErrorAction SilentlyContinue | Get-VMHost if ($tempList) { $vHostList += $tempList | Sort-Object -Property Name } else { Write-Warning -Message "`tDatacenter with name $vDCname was not found in $Global:DefaultViServers" } #END if/else } #END foreach } #END if/else } #END if/else } else { Write-Verbose -Message ((Get-Date -Format G) + "`tExecuting Cmdlet using cluster parameter") Write-Host "`tGathering host list from the following Cluster(s): " (@($cluster) -join ',') foreach ($vClusterName in $cluster) { $tempList = Get-Cluster -Name $vClusterName.Trim() -ErrorAction SilentlyContinue | Get-VMHost if ($tempList) { $vHostList += $tempList | Sort-Object -Property Name } else { Write-Warning -Message "`tCluster with name $vClusterName was not found in $Global:DefaultViServers" } #END if/else } #END foreach } #END if/else } else { Write-Verbose -Message ((Get-Date -Format G) + "`tExecuting Cmdlet using esxi parameter") Write-Host "`tGathering host list..." foreach ($invidualHost in $esxi) { $tempList = Get-VMHost -Name $invidualHost.Trim() -ErrorAction SilentlyContinue if ($tempList) { $vHostList += $tempList | Sort-Object -Property Name } else { Write-Warning -Message "`tESXi host $invidualHost was not found in $Global:DefaultViServers" } #END if/else } #END foreach } #END if/else $tempList = $null <# Validate export switches, folder path and dependencies #> Write-Verbose -Message ((Get-Date -Format G) + "`tValidate export switches and folder path") if ($ExportCSV -or $ExportExcel) { $currentLocation = (Get-Location).Path if ([string]::IsNullOrWhiteSpace($folderPath)) { Write-Verbose -Message ((Get-Date -Format G) + "`t-folderPath parameter is Null or Empty") Write-Warning -Message "`tFolder Path (-folderPath) was not specified for saving exported data. The current location: '$currentLocation' will be used" $outputFile = $currentLocation + "\" + $outputFile } else { if (Test-Path $folderPath) { Write-Verbose -Message ((Get-Date -Format G) + "`t'$folderPath' path found") $lastCharsOfFolderPath = $folderPath.Substring($folderPath.Length - 1) if ($lastCharsOfFolderPath -eq "\" -or $lastCharsOfFolderPath -eq "/") { $outputFile = $folderPath + $outputFile } else { $outputFile = $folderPath + "\" + $outputFile } #END if/else Write-Verbose -Message ((Get-Date -Format G) + "`t$outputFile") } else { Write-Warning -Message "`t'$folderPath' path not found. The current location: '$currentLocation' will be used instead" $outputFile = $currentLocation + "\" + $outputFile } #END if/else } #END if/else } #END if if ($ExportExcel) { if (Get-Module -ListAvailable -Name ImportExcel) { Write-Verbose -Message ((Get-Date -Format G) + "`tImportExcel Module available") } else { Write-Warning -Message "`tImportExcel Module missing. Will export data to CSV file instead" Write-Warning -Message "`tImportExcel Module can be installed directly from the PowerShell Gallery" Write-Warning -Message "`tSee https://github.com/dfinke/ImportExcel for more information" $ExportExcel = $false $ExportCSV = $true } #END if/else } #END if <# Validate that a Cmdlet switch was used. Options are -StorageAdapters, -Datastores. By default all are executed unless one is specified. #> Write-Verbose -Message ((Get-Date -Format G) + "`tValidate Cmdlet switches") if ($StorageAdapters -or $Datastores) { Write-Verbose -Message ((Get-Date -Format G) + "`tA Cmdlet switch was specified") } else { Write-Verbose -Message ((Get-Date -Format G) + "`tA Cmdlet switch was not specified") Write-Verbose -Message ((Get-Date -Format G) + "`tWill execute all (-StorageAdapters -Datastores)") $StorageAdapters = $true $Datastores = $true } #END if/else <# Main code execution #> foreach ($vmhost in $vHostList) { <# Skip if ESXi host is not in a Connected or Maintenance ConnectionState #> Write-Verbose -Message ((Get-Date -Format G) + "`t$vmhost Connection State: " + $vmhost.ConnectionState) if ($vmhost.ConnectionState -eq "Connected" -or $vmhost.ConnectionState -eq "Maintenance") { <# Do nothing - ESXi host is reachable #> } else { <# Use a custom object to keep track of skipped hosts and continue to the next foreach loop #> $skipCollection += [pscustomobject]@{ 'Hostname' = $vmhost.Name 'Connection State' = $vmhost.ConnectionState } #END [PSCustomObject] continue } #END if/else $esxcli1 = Get-EsxCli -VMHost $vmhost -V2 <# Get Storage adapters (HBA) details #> if ($StorageAdapters) { Write-Host "`tGathering storage adapter details from $vmhost ..." <# Get iSCSI HBA Details #> Write-Verbose -Message ((Get-Date -Format G) + "`tGet iSCSI Software Adapter...") if ($hba = $vmhost | Get-VMHostHba -Type iScsi | Where-Object {$_.Model -eq "iSCSI Software Adapter"}) { Write-Verbose -Message ((Get-Date -Format G) + "`tGet iSCSI HBA details for: " + $hba.Device) $hbaBinding = $esxcli1.iscsi.networkportal.list.Invoke(@{adapter = $hba.Device}) $hbaTarget = Get-IScsiHbaTarget -IScsiHba $hba $sendList = $hbaTarget | Where-Object {$_.Type -eq "Send"} | Select-Object -ExpandProperty Address $staticList = $hbaTarget | Where-Object {$_.Type -eq "Static"} | Select-Object -ExpandProperty Address <# Get active physical adapters based on PortGroup.Test both standard and distributed vSwitch #> foreach ($vmkNic in $hbaBinding) { Write-Verbose -Message ((Get-Date -Format G) + "`tGet active physical adapter for: " + $vmkNic.PortGroup) $vmNic = $vmhost | Get-VMHostNetworkAdapter | Where-Object {$_.Mac -eq $vmkNic.MACAddress} $nicList = $esxcli1.network.nic.list.Invoke() | Where-Object {$_.Name -eq $vmNic.Name} $portGroupTeam = Get-VirtualPortGroup -VMhost $vmhost -Name $vmkNic.PortGroup | Where-Object {$_.VirtualSwitchName -eq $vmkNic.Vswitch} | Get-NicTeamingPolicy if ($portGroup = Get-VirtualPortGroup -VMhost $vmhost -Name $vmkNic.PortGroup -Standard -ErrorAction SilentlyContinue | Where-Object {$_.VirtualSwitchName -eq $vmkNic.Vswitch}) { Write-Verbose -Message ((Get-Date -Format G) + "`tStandard vSwitch") $portGroupTeam = $portGroup | Get-NicTeamingPolicy $vSwitch = $esxcli1.network.vswitch.standard.list.Invoke(@{vswitchname = $vmkNic.Vswitch}) $activeAdapters = (@($PortGroupTeam.ActiveNic) -join ',') } else { Write-Verbose -Message ((Get-Date -Format G) + "`tDistributed vSwitch") $portGroup = Get-VDPortgroup -Name $vmkNic.PortGroup -VDSwitch $vmkNic.Vswitch -ErrorAction SilentlyContinue $portGroupTeam = $portGroup | Get-VDUplinkTeamingPolicy $vSwitch = $esxcli1.network.vswitch.dvs.vmware.list.Invoke(@{vdsname = $vmkNic.Vswitch}) $activeAdapters = (@($PortGroupTeam.ActiveUplinkPort) -join ',') } #END if/else <# Use a custom object to store collected data #> $iSCSICollection += [PSCustomObject]@{ 'Hostname' = $vmhost.Name 'Device' = $hba.Device 'iSCSI Name' = $hba.IScsiName 'Model' = $hba.Model 'Send Targets' = (@($sendList) -join ',') 'Static Tarets' = (@($staticList) -join ',') 'Port Group' = $vmkNic.PortGroup + " (" + $vmkNic.Vswitch + ")" 'VMkernel Adapter' = $vmkNic.Vmknic 'Port Binding' = $vmkNic.CompliantStatus 'Path Status' = $vmkNic.PathStatus 'Physical Network Adapter' = $vmNic.Name + " (" + $vmnic.BitRatePerSec / 1000 + " Gbit/s, " + $nicList.Duplex + ")" } #END [PSCustomObject] } #END foreach } #END if <# Get Fibre Channel HBA details #> Write-Verbose -Message ((Get-Date -Format G) + "`tGet Fibre Channel Adapter...") if ($hba = $vmhost | Get-VMHostHba -Type FibreChannel) { foreach ($hbaDevice in $hba) { Write-Verbose -Message ((Get-Date -Format G) + "`tGet Fibre Channel HBA details for: " + $hbaDevice.Device) $nodeWWN = ([String]::Format("{0:X}", $HbaDevice.NodeWorldWideName) -split "(\w{2})" | Where-Object {$_ -ne ""}) -join ":" $portWWN = ([String]::Format("{0:X}", $HbaDevice.PortWorldWideName) -split "(\w{2})" | Where-Object {$_ -ne ""}) -join ":" <# Use a custom object to store collected data #> $FibreChannelCollection += [PSCustomObject]@{ 'Hostname' = $vmhost.Name 'Device' = $hbaDevice.Device 'Model' = $hbaDevice.Model 'Node WWN' = $nodeWWN 'Port WWN' = $portWWN 'Driver' = $hbaDevice.Driver 'Speed (Gb)' = $hbaDevice.Speed 'Status' = $hbaDevice.Status } #END [PSCustomObject] } # END foreach } #END if } #END if <# Get Datastores details #> if ($Datastores) { Write-Host "`tGathering Datastore details from $vmhost ..." $hostDSList = $vmhost | Get-Datastore | Sort-Object -Property Name foreach ($oneDS in $hostDSList) { Write-Verbose -Message ((Get-Date -Format G) + "`tGet Datastore details for: " + $oneDS.Name) $dsCName = $oneDS.ExtensionData.Info.Vmfs.Extent | Select-Object -ExpandProperty DiskName if ($oneDS.Type -eq "vsan" -or $oneDS.Type -eq "NFS") { Write-Verbose -Message ((Get-Date -Format G) + "`t" + $oneDS.Type + " type datastore found. Skipping storage multipathing policy validation") $dsDisk = $null } else { $dsDisk = $esxcli1.storage.nmp.device.list.Invoke(@{device = $dsCName}) } #END if/else <# Validate against exising collection to speed up foreach #> $itemInCollection = $DatastoresCollection | Where-Object {$_.'Canonical Name' -like $dsCName} | Select-Object -First 1 if ($itemInCollection) { Write-Verbose -Message ((Get-Date -Format G) + "`t$dsCName already in collection; will reuse associated properties") $dsName = $itemInCollection.'Datastore Name' $dsDisplayName = $itemInCollection.'Device Name' $LUN = $itemInCollection.LUN $dsType = $itemInCollection.Type $dsCluster = $itemInCollection.'Datastore Cluster' $dsCapacityGB = $itemInCollection.'Capacity (GB)' $ProvisionedGB = $itemInCollection.'Provisioned Space (GB)' $dsFreeGB = $itemInCollection.'Free Space (GB)' $dsTransportType = $itemInCollection.Transport $dsMountPoint = $itemInCollection.'Mount Point' $dsFileSystem = $itemInCollection.'File System Version' } else { Write-Verbose -Message ((Get-Date -Format G) + "`t$dsCName not yet in collection; will query associated properties") $dsView = $oneDS | Get-View $dsSummary = $dsView | Select-Object -ExpandProperty Summary $provisionedGB = [math]::round(($dsSummary.Capacity - $dsSummary.FreeSpace + $dsSummary.Uncommitted) / 1GB, 2) if ($oneDS.Type -eq "vsan" -or $oneDS.Type -eq "NFS") { Write-Verbose -Message ((Get-Date -Format G) + "`t" + $oneDS.Type + " type datastore found. Skipping storage path validation") $dsDisplayName = $null $LUN = $null $dsTransport = $null } else { $dspath = $esxcli1.storage.core.path.list.Invoke(@{device = $dsCName}) | Select-Object -First 1 $dsDisplayName = (($dspath.DeviceDisplayName -Split " [(]")[0]) $LUN = $dspath.LUN $vmHBA = $dspath.Adapter $dsTransport = $vmhost | Get-VMHostHba | Select-Object Device, Type | Where-Object {$_.Device -eq $vmHBA} } #END if/else if ($oneDS.ParentFolder -eq $null -and $oneDS.ParentFolderId -match "StoragePod") { $dsCluster = Get-DatastoreCluster -Id $oneDS.ParentFolderId | Select-Object -ExpandProperty Name Write-Verbose -Message ((Get-Date -Format G) + "`tDatastore is part of Datastore Cluster: " + $dsCluster) } else { $dsCluster = $null Write-Verbose -Message ((Get-Date -Format G) + "`tDatastore not part of a Datastore Cluster") } #END if/else $dsName = $oneDS.Name $dsType = $oneDS.Type $dsCapacityGB = [math]::round($oneDS.CapacityGB, 2) $dsFreeGB = [math]::round($oneDS.FreeSpaceGB, 2) $dsTransportType = $dsTransport.Type $dsMountPoint = (($dsSummary.Url -split "ds://")[1]) $dsFileSystem = $oneDS.FileSystemVersion } #END if/else <# Use a custom object to store collected data #> $DatastoresCollection += [PSCustomObject]@{ 'Hostname' = $vmhost.Name 'Datastore Name' = $dsName 'Device Name' = $dsDisplayName 'Canonical Name' = $dsCName 'LUN' = $LUN 'Type' = $dsType 'Datastore Cluster' = $dsCluster 'Capacity (GB)' = $dsCapacityGB 'Provisioned Space (GB)' = $ProvisionedGB 'Free Space (GB)' = $dsFreeGB 'Transport' = $dsTransportType 'Mount Point' = $dsMountPoint 'Multipath Policy' = $dsDisk.PathSelectionPolicy 'File System Version' = $dsFileSystem } #END [PSCustomObject] } #END foreach } #END if } #END foreach Write-Verbose -Message ((Get-Date -Format G) + "`tMain code execution completed") <# Display skipped hosts and their connection status #> If ($skipCollection) { Write-Warning -Message "`tCheck Connection State or Host name " Write-Warning -Message "`tSkipped hosts: " $skipCollection | Format-Table -AutoSize } #END if <# Validate output arrays #> if ($iSCSICollection -or $FibreChannelCollection -or $DatastoresCollection) { Write-Verbose -Message ((Get-Date -Format G) + "`tInformation gathered") } else { Write-Verbose -Message ((Get-Date -Format G) + "`tNo information gathered") } #END if/else <# Output to screen Export data to CSV, Excel #> if ($iSCSICollection) { Write-Host "`n" "ESXi Storage iSCSI HBA:" -ForegroundColor Green if ($ExportCSV) { $iSCSICollection | Export-Csv ($outputFile + "iSCSI_HBA.csv") -NoTypeInformation Write-Host "`tData exported to" ($outputFile + "iSCSI_HBA.csv") "file" -ForegroundColor Green } elseif ($ExportExcel) { $iSCSICollection | Export-Excel ($outputFile + ".xlsx") -WorkSheetname iSCSI_HBA -NoNumberConversion * -AutoSize -BoldTopRow Write-Host "`tData exported to" ($outputFile + ".xlsx") "file" -ForegroundColor Green } elseif ($PassThru) { $iSCSICollection } else { $iSCSICollection | Format-List } #END if/else } #END if if ($FibreChannelCollection) { Write-Host "`n" "ESXi FibreChannel HBA:" -ForegroundColor Green if ($ExportCSV) { $FibreChannelCollection | Export-Csv ($outputFile + "FibreChannelHBA.csv") -NoTypeInformation Write-Host "`tData exported to" ($outputFile + "FibreChannelHBA.csv") "file" -ForegroundColor Green } elseif ($ExportExcel) { $FibreChannelCollection | Export-Excel ($outputFile + ".xlsx") -WorkSheetname FibreChannel_HBA -NoNumberConversion * -AutoSize -BoldTopRow Write-Host "`tData exported to" ($outputFile + ".xlsx") "file" -ForegroundColor Green } elseif ($PassThru) { $FibreChannelCollection } else { $FibreChannelCollection | Format-List } #END if/else } #END if if ($DatastoresCollection) { Write-Host "`n" "ESXi Datastores:" -ForegroundColor Green if ($ExportCSV) { $DatastoresCollection | Export-Csv ($outputFile + "Datastores.csv") -NoTypeInformation Write-Host "`tData exported to" ($outputFile + "Datastores.csv") "file" -ForegroundColor Green } elseif ($ExportExcel) { $DatastoresCollection | Export-Excel ($outputFile + ".xlsx") -WorkSheetname Datastores -NoNumberConversion * -AutoSize -BoldTopRow Write-Host "`tData exported to" ($outputFile + ".xlsx") "file" -ForegroundColor Green } elseif ($PassThru) { $DatastoresCollection } else { $DatastoresCollection | Format-List }#END if/else } #END if } #END function |