Linux でのPowerShell(PowerCLI)

## PowerSellCore
クロスプラットフォームのOSS版PowerShell。
Linuxで動くPowerShellです。

[PowerShell Coreとは](https://news.mynavi.jp/itsearch/article/devsoft/3625)

これを使ってWSL + PowerCLICoreでvSphere上のオペレーションをコードで実行してみます。

## 前提

| Name | Version |
| --- | --- |
| Ubuntu(WSL) | Ubuntu 18.04.1 LTS  |
| PowerShellCore | 6.1.1 |
| PowerCLICore | 11.0.0.10336080 | 

## インストール
[Linux への PowerShell Core のインストール](https://docs.microsoft.com/ja-jp/powershell/scripting/setup/installing-powershell-core-on-linux?view=powershell-6#ubuntu-1804)

### Ubuntu 18.04

```sh
# Download the Microsoft repository GPG keys
wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb

# Register the Microsoft repository GPG keys
sudo dpkg -i packages-microsoft-prod.deb

# Update the list of products
sudo apt-get update

# Install PowerShell
sudo apt-get install -y powershell

# Start PowerShell
pwsh
```

### バージョン確認
```
> pwsh --version
PowerShell 6.1.1
```

### PowerCLICoreインストール
正確にはPowerCLICoreというものは無くなり、PowerCLIに統合されたようです。
モジュールがPowerShellGalleryに公開され、インストールもInstall-Moduleを使う事で簡単にインストールできるようになりました。

```
> Install-Module -Name VMware.PowerCLI
```
プロキシがある時は`-Proxy "http://server:port"`とかを付けます。


## 実行準備

### 現在使えるモジュールを確認
ちょい昔はモジュールの数が少なくてCoreぐらいしかなかったみたいなのですが、現在はかなり充実し、色々できるようになっているようです。

```
| Name | Version | Commands |
| --- | --- | --- |
| VMware.DeployAutomation | 6.7.0.8250345 | [Add-DeployRule, Add-DeployRule],[Add-ProxyServer, Add-ProxyServer],[Add-ScriptBundle, Add-ScriptBundle],[Copy-DeployRule, Copy-DeployRule],[Export-AutoDeployState, Export-AutoDeployState],[Get-DeployOption, Get-DeployOption],[Get-DeployRule, Get-DeployRule],[Get-DeployRuleSet, Get-DeployRuleSet],[Get-ProxyServer, Get-ProxyServer],[Get-ScriptBundle, Get-ScriptBundle],[Get-VMHostAttributes, Get-VMHostAttributes],[Get-VMHostImageProfile, Get-VMHostImageProfile],[Get-VMHostMatchingRules, Get-VMHostMatchingRules],[Import-AutoDeployState, Import-AutoDeployState],[New-DeployRule, New-DeployRule],[Remove-DeployRule, Remove-DeployRule],[Remove-ProxyServer, Remove-ProxyServer],[Remove-ScriptBundle, Remove-ScriptBundle],[Repair-DeployImageCache, Repair-DeployImageCache],[Repair-DeployRuleSetCompliance, Repair-DeployRuleSetCompliance],[Set-DeployOption, Set-DeployOption],[Set-DeployRule, Set-DeployRule],[Set-DeployRuleSet, Set-DeployRuleSet],[Set-ESXImageProfileAssociation, Set-ESXImageProfileAssociation],[Set-ScriptBundleAssociation, Set-ScriptBundleAssociation],[Switch-ActiveDeployRuleSet, Switch-ActiveDeployRuleSet],[Test-DeployRuleSetCompliance, Test-DeployRuleSetCompliance],[Apply-ESXImageProfile, Apply-ESXImageProfile],[Get-DeployCommand, Get-DeployCommand] |
| VMware.ImageBuilder | 6.7.0.8250345 | [Add-EsxSoftwareDepot, Add-EsxSoftwareDepot],[Add-EsxSoftwarePackage, Add-EsxSoftwarePackage],[Compare-EsxImageProfile, Compare-EsxImageProfile],[Export-EsxImageProfile, Export-EsxImageProfile],[Get-EsxImageProfile, Get-EsxImageProfile],[Get-EsxSoftwareDepot, Get-EsxSoftwareDepot],[Get-EsxSoftwarePackage, Get-EsxSoftwarePackage],[New-EsxImageProfile, New-EsxImageProfile],[Remove-EsxImageProfile, Remove-EsxImageProfile],[Remove-EsxSoftwareDepot, Remove-EsxSoftwareDepot],[Remove-EsxSoftwarePackage, Remove-EsxSoftwarePackage],[Set-EsxImageProfile, Set-EsxImageProfile] |
| VMware.PowerCLI | 11.0.0.10380590 |  |
| VMware.Vim | 6.7.0.10334489 |  |
| VMware.VimAutomation.Cis.Core | 11.0.0.10335701 | [Connect-CisServer, Connect-CisServer],[Disconnect-CisServer, Disconnect-CisServer],[Get-CisService, Get-CisService] |
| VMware.VimAutomation.Cloud | 11.0.0.10379994 | [Add-CIDatastore, Add-CIDatastore],[Connect-CIServer, Connect-CIServer],[Disconnect-CIServer, Disconnect-CIServer],[Get-Catalog, Get-Catalog],[Get-CIAccessControlRule, Get-CIAccessControlRule],[Get-CIDatastore, Get-CIDatastore],[Get-CINetworkAdapter, Get-CINetworkAdapter],[Get-CIRole, Get-CIRole],[Get-CIUser, Get-CIUser],[Get-CIVApp, Get-CIVApp],[Get-CIVAppNetwork, Get-CIVAppNetwork],[Get-CIVAppStartRule, Get-CIVAppStartRule],[Get-CIVAppTemplate, Get-CIVAppTemplate],[Get-CIView, Get-CIView],[Get-CIVM, Get-CIVM],[Get-CIVMTemplate, Get-CIVMTemplate],[Get-EdgeGateway, Get-EdgeGateway],[Get-ExternalNetwork, Get-ExternalNetwork],[Get-Media, Get-Media],[Get-NetworkPool, Get-NetworkPool],[Get-Org, Get-Org],[Get-OrgNetwork, Get-OrgNetwork],[Get-OrgVdc, Get-OrgVdc],[Get-OrgVdcNetwork, Get-OrgVdcNetwork],[Get-ProviderVdc, Get-ProviderVdc],[Import-CIVApp, Import-CIVApp],[Import-CIVAppTemplate, Import-CIVAppTemplate],[New-CIAccessControlRule, New-CIAccessControlRule],[New-CIVApp, New-CIVApp],[New-CIVAppNetwork, New-CIVAppNetwork],[New-CIVAppTemplate, New-CIVAppTemplate],[New-CIVM, New-CIVM],[New-Org, New-Org],[New-OrgNetwork, New-OrgNetwork],[New-OrgVdc, New-OrgVdc],[New-OrgVdcNetwork, New-OrgVdcNetwork],[Remove-CIAccessControlRule, Remove-CIAccessControlRule],[Remove-CIVApp, Remove-CIVApp],[Remove-CIVAppNetwork, Remove-CIVAppNetwork],[Remove-CIVAppTemplate, Remove-CIVAppTemplate],[Remove-Org, Remove-Org],[Remove-OrgNetwork, Remove-OrgNetwork],[Remove-OrgVdc, Remove-OrgVdc],[Remove-OrgVdcNetwork, Remove-OrgVdcNetwork],[Restart-CIVApp, Restart-CIVApp],[Restart-CIVAppGuest, Restart-CIVAppGuest],[Restart-CIVM, Restart-CIVM],[Restart-CIVMGuest, Restart-CIVMGuest],[Search-Cloud, Search-Cloud],[Set-CIAccessControlRule, Set-CIAccessControlRule],[Set-CINetworkAdapter, Set-CINetworkAdapter],[Set-CIVApp, Set-CIVApp],[Set-CIVAppNetwork, Set-CIVAppNetwork],[Set-CIVAppStartRule, Set-CIVAppStartRule],[Set-CIVAppTemplate, Set-CIVAppTemplate],[Set-Org, Set-Org],[Set-OrgNetwork, Set-OrgNetwork],[Set-OrgVdc, Set-OrgVdc],[Set-OrgVdcNetwork, Set-OrgVdcNetwork],[Start-CIVApp, Start-CIVApp],[Start-CIVM, Start-CIVM],[Stop-CIVApp, Stop-CIVApp],[Stop-CIVAppGuest, Stop-CIVAppGuest],[Stop-CIVM, Stop-CIVM],[Stop-CIVMGuest, Stop-CIVMGuest],[Suspend-CIVApp, Suspend-CIVApp],[Suspend-CIVM, Suspend-CIVM],[Connect-PIComputeInstance, Connect-PIComputeInstance],[Connect-PIDatacenter, Connect-PIDatacenter],[Disconnect-PIComputeInstance, Disconnect-PIComputeInstance],[Disconnect-PIDatacenter, Disconnect-PIDatacenter],[Get-PIAccessControlRule, Get-PIAccessControlRule],[Get-PINetworkAdapter, Get-PINetworkAdapter],[Get-PIUser, Get-PIUser],[Get-PIVApp, Get-PIVApp],[Get-PIVAppNetwork, Get-PIVAppNetwork],[Get-PIVAppStartRule, Get-PIVAppStartRule],[Get-PIVAppTemplate, Get-PIVAppTemplate],[Get-PIVM, Get-PIVM],[Get-PIVMTemplate, Get-PIVMTemplate],[Import-PIVAppTemplate, Import-PIVAppTemplate],[New-PIAccessControlRule, New-PIAccessControlRule],[New-PIVApp, New-PIVApp],[New-PIVAppNetwork, New-PIVAppNetwork],[New-PIVAppTemplate, New-PIVAppTemplate],[New-PIVM, New-PIVM],[Remove-PIAccessControlRule, Remove-PIAccessControlRule],[Remove-PIVApp, Remove-PIVApp],[Remove-PIVAppNetwork, Remove-PIVAppNetwork],[Remove-PIVAppTemplate, Remove-PIVAppTemplate],[Restart-PIVApp, Restart-PIVApp],[Restart-PIVAppGuest, Restart-PIVAppGuest],[Restart-PIVM, Restart-PIVM],[Restart-PIVMGuest, Restart-PIVMGuest],[Set-PIAccessControlRule, Set-PIAccessControlRule],[Set-PINetworkAdapter, Set-PINetworkAdapter],[Set-PIVApp, Set-PIVApp],[Set-PIVAppNetwork, Set-PIVAppNetwork],[Set-PIVAppStartRule, Set-PIVAppStartRule],[Set-PIVAppTemplate, Set-PIVAppTemplate],[Start-PIVApp, Start-PIVApp],[Start-PIVM, Start-PIVM],[Stop-PIVApp, Stop-PIVApp],[Stop-PIVAppGuest, Stop-PIVAppGuest],[Stop-PIVM, Stop-PIVM],[Stop-PIVMGuest, Stop-PIVMGuest],[Suspend-CIVAppGuest, Suspend-CIVAppGuest],[Suspend-PIVApp, Suspend-PIVApp],[Suspend-PIVAppGuest, Suspend-PIVAppGuest],[Suspend-PIVM, Suspend-PIVM] |
| VMware.VimAutomation.Common | 11.0.0.10334497 |  |
| VMware.VimAutomation.Core | 11.0.0.10336080 | [Add-PassthroughDevice, Add-PassthroughDevice],[Add-VirtualSwitchPhysicalNetworkAdapter, Add-VirtualSwitchPhysicalNetworkAdapter],[Add-VMHost, Add-VMHost],[Add-VMHostNtpServer, Add-VMHostNtpServer],[Connect-VIServer, Connect-VIServer],[Copy-DatastoreItem, Copy-DatastoreItem],[Copy-HardDisk, Copy-HardDisk],[Copy-VMGuestFile, Copy-VMGuestFile],[Disconnect-VIServer, Disconnect-VIServer],[Dismount-Tools, Dismount-Tools],[Export-VApp, Export-VApp],[Export-VMHostProfile, Export-VMHostProfile],[Format-VMHostDiskPartition, Format-VMHostDiskPartition],[Get-AdvancedSetting, Get-AdvancedSetting],[Get-AlarmAction, Get-AlarmAction],[Get-AlarmActionTrigger, Get-AlarmActionTrigger],[Get-AlarmDefinition, Get-AlarmDefinition],[Get-Annotation, Get-Annotation],[Get-CDDrive, Get-CDDrive],[Get-Cluster, Get-Cluster],[Get-ContentLibraryItem, Get-ContentLibraryItem],[Get-CustomAttribute, Get-CustomAttribute],[Get-Datacenter, Get-Datacenter],[Get-Datastore, Get-Datastore],[Get-DatastoreCluster, Get-DatastoreCluster],[Get-DrsClusterGroup, Get-DrsClusterGroup],[Get-DrsRecommendation, Get-DrsRecommendation],[Get-DrsRule, Get-DrsRule],[Get-DrsVMHostRule, Get-DrsVMHostRule],[Get-EsxCli, Get-EsxCli],[Get-EsxTop, Get-EsxTop],[Get-FloppyDrive, Get-FloppyDrive],[Get-Folder, Get-Folder],[Get-HAPrimaryVMHost, Get-HAPrimaryVMHost],[Get-HardDisk, Get-HardDisk],[Get-Inventory, Get-Inventory],[Get-IScsiHbaTarget, Get-IScsiHbaTarget],[Get-Log, Get-Log],[Get-LogType, Get-LogType],[Get-NetworkAdapter, Get-NetworkAdapter],[Get-NicTeamingPolicy, Get-NicTeamingPolicy],[Get-OSCustomizationNicMapping, Get-OSCustomizationNicMapping],[Get-OSCustomizationSpec, Get-OSCustomizationSpec],[Get-OvfConfiguration, Get-OvfConfiguration],[Get-PassthroughDevice, Get-PassthroughDevice],[Get-PowerCLIConfiguration, Get-PowerCLIConfiguration],[Get-PowerCLIVersion, Get-PowerCLIVersion],[Get-ResourcePool, Get-ResourcePool],[Get-ScsiController, Get-ScsiController],[Get-ScsiLun, Get-ScsiLun],[Get-ScsiLunPath, Get-ScsiLunPath],[Get-SecurityPolicy, Get-SecurityPolicy],[Get-Snapshot, Get-Snapshot],[Get-Stat, Get-Stat],[Get-StatInterval, Get-StatInterval],[Get-StatType, Get-StatType],[Get-Tag, Get-Tag],[Get-TagAssignment, Get-TagAssignment],[Get-TagCategory, Get-TagCategory],[Get-Task, Get-Task],[Get-Template, Get-Template],[Get-UsbDevice, Get-UsbDevice],[Get-VApp, Get-VApp],[Get-VIAccount, Get-VIAccount],[Get-VICredentialStoreItem, Get-VICredentialStoreItem],[Get-VIEvent, Get-VIEvent],[Get-View, Get-View],[Get-VIObjectByVIView, Get-VIObjectByVIView],[Get-VIPermission, Get-VIPermission],[Get-VIPrivilege, Get-VIPrivilege],[Get-VIProperty, Get-VIProperty],[Get-VIRole, Get-VIRole],[Get-VirtualPortGroup, Get-VirtualPortGroup],[Get-VirtualSwitch, Get-VirtualSwitch],[Get-VM, Get-VM],[Get-VMGuest, Get-VMGuest],[Get-VMHost, Get-VMHost],[Get-VMHostAccount, Get-VMHostAccount],[Get-VMHostAdvancedConfiguration, Get-VMHostAdvancedConfiguration],[Get-VMHostAuthentication, Get-VMHostAuthentication],[Get-VMHostAvailableTimeZone, Get-VMHostAvailableTimeZone],[Get-VMHostDiagnosticPartition, Get-VMHostDiagnosticPartition],[Get-VMHostDisk, Get-VMHostDisk],[Get-VMHostDiskPartition, Get-VMHostDiskPartition],[Get-VMHostFirewallDefaultPolicy, Get-VMHostFirewallDefaultPolicy],[Get-VMHostFirewallException, Get-VMHostFirewallException],[Get-VMHostFirmware, Get-VMHostFirmware],[Get-VMHostHardware, Get-VMHostHardware],[Get-VMHostHba, Get-VMHostHba],[Get-VMHostModule, Get-VMHostModule],[Get-VMHostNetwork, Get-VMHostNetwork],[Get-VMHostNetworkAdapter, Get-VMHostNetworkAdapter],[Get-VMHostNtpServer, Get-VMHostNtpServer],[Get-VMHostPatch, Get-VMHostPatch],[Get-VMHostPciDevice, Get-VMHostPciDevice],[Get-VMHostProfile, Get-VMHostProfile],[Get-VMHostProfileImageCacheConfiguration, Get-VMHostProfileImageCacheConfiguration],[Get-VMHostProfileRequiredInput, Get-VMHostProfileRequiredInput],[Get-VMHostProfileStorageDeviceConfiguration, Get-VMHostProfileStorageDeviceConfiguration],[Get-VMHostProfileUserConfiguration, Get-VMHostProfileUserConfiguration],[Get-VMHostProfileVmPortGroupConfiguration, Get-VMHostProfileVmPortGroupConfiguration],[Get-VMHostRoute, Get-VMHostRoute],[Get-VMHostService, Get-VMHostService],[Get-VMHostSnmp, Get-VMHostSnmp],[Get-VMHostStartPolicy, Get-VMHostStartPolicy],[Get-VMHostStorage, Get-VMHostStorage],[Get-VMHostSysLogServer, Get-VMHostSysLogServer],[Get-VMQuestion, Get-VMQuestion],[Get-VMResourceConfiguration, Get-VMResourceConfiguration],[Get-VMStartPolicy, Get-VMStartPolicy],[Import-VApp, Import-VApp],[Import-VMHostProfile, Import-VMHostProfile],[Install-VMHostPatch, Install-VMHostPatch],[Invoke-DrsRecommendation, Invoke-DrsRecommendation],[Invoke-VMHostProfile, Invoke-VMHostProfile],[Invoke-VMScript, Invoke-VMScript],[Mount-Tools, Mount-Tools],[Move-Cluster, Move-Cluster],[Move-Datacenter, Move-Datacenter],[Move-Datastore, Move-Datastore],[Move-Folder, Move-Folder],[Move-HardDisk, Move-HardDisk],[Move-Inventory, Move-Inventory],[Move-ResourcePool, Move-ResourcePool],[Move-Template, Move-Template],[Move-VApp, Move-VApp],[Move-VM, Move-VM],[Move-VMHost, Move-VMHost],[New-AdvancedSetting, New-AdvancedSetting],[New-AlarmAction, New-AlarmAction],[New-AlarmActionTrigger, New-AlarmActionTrigger],[New-CDDrive, New-CDDrive],[New-Cluster, New-Cluster],[New-CustomAttribute, New-CustomAttribute],[New-Datacenter, New-Datacenter],[New-Datastore, New-Datastore],[New-DatastoreCluster, New-DatastoreCluster],[New-DrsClusterGroup, New-DrsClusterGroup],[New-DrsRule, New-DrsRule],[New-DrsVMHostRule, New-DrsVMHostRule],[New-FloppyDrive, New-FloppyDrive],[New-Folder, New-Folder],[New-HardDisk, New-HardDisk],[New-IScsiHbaTarget, New-IScsiHbaTarget],[New-NetworkAdapter, New-NetworkAdapter],[New-OSCustomizationNicMapping, New-OSCustomizationNicMapping],[New-OSCustomizationSpec, New-OSCustomizationSpec],[New-ResourcePool, New-ResourcePool],[New-ScsiController, New-ScsiController],[New-Snapshot, New-Snapshot],[New-StatInterval, New-StatInterval],[New-Tag, New-Tag],[New-TagAssignment, New-TagAssignment],[New-TagCategory, New-TagCategory],[New-Template, New-Template],[New-VApp, New-VApp],[New-VICredentialStoreItem, New-VICredentialStoreItem],[New-VIPermission, New-VIPermission],[New-VIProperty, New-VIProperty],[New-VIRole, New-VIRole],[New-VirtualPortGroup, New-VirtualPortGroup],[New-VirtualSwitch, New-VirtualSwitch],[New-VM, New-VM],[New-VMHostAccount, New-VMHostAccount],[New-VMHostNetworkAdapter, New-VMHostNetworkAdapter],[New-VMHostProfile, New-VMHostProfile],[New-VMHostProfileVmPortGroupConfiguration, New-VMHostProfileVmPortGroupConfiguration],[New-VMHostRoute, New-VMHostRoute],[Open-VMConsoleWindow, Open-VMConsoleWindow],[Remove-AdvancedSetting, Remove-AdvancedSetting],[Remove-AlarmAction, Remove-AlarmAction],[Remove-AlarmActionTrigger, Remove-AlarmActionTrigger],[Remove-CDDrive, Remove-CDDrive],[Remove-Cluster, Remove-Cluster],[Remove-CustomAttribute, Remove-CustomAttribute],[Remove-Datacenter, Remove-Datacenter],[Remove-Datastore, Remove-Datastore],[Remove-DatastoreCluster, Remove-DatastoreCluster],[Remove-DrsClusterGroup, Remove-DrsClusterGroup],[Remove-DrsRule, Remove-DrsRule],[Remove-DrsVMHostRule, Remove-DrsVMHostRule],[Remove-FloppyDrive, Remove-FloppyDrive],[Remove-Folder, Remove-Folder],[Remove-HardDisk, Remove-HardDisk],[Remove-Inventory, Remove-Inventory],[Remove-IScsiHbaTarget, Remove-IScsiHbaTarget],[Remove-NetworkAdapter, Remove-NetworkAdapter],[Remove-OSCustomizationNicMapping, Remove-OSCustomizationNicMapping],[Remove-OSCustomizationSpec, Remove-OSCustomizationSpec],[Remove-PassthroughDevice, Remove-PassthroughDevice],[Remove-ResourcePool, Remove-ResourcePool],[Remove-Snapshot, Remove-Snapshot],[Remove-StatInterval, Remove-StatInterval],[Remove-Tag, Remove-Tag],[Remove-TagAssignment, Remove-TagAssignment],[Remove-TagCategory, Remove-TagCategory],[Remove-Template, Remove-Template],[Remove-UsbDevice, Remove-UsbDevice],[Remove-VApp, Remove-VApp],[Remove-VICredentialStoreItem, Remove-VICredentialStoreItem],[Remove-VIPermission, Remove-VIPermission],[Remove-VIProperty, Remove-VIProperty],[Remove-VIRole, Remove-VIRole],[Remove-VirtualPortGroup, Remove-VirtualPortGroup],[Remove-VirtualSwitch, Remove-VirtualSwitch],[Remove-VirtualSwitchPhysicalNetworkAdapter, Remove-VirtualSwitchPhysicalNetworkAdapter],[Remove-VM, Remove-VM],[Remove-VMHost, Remove-VMHost],[Remove-VMHostAccount, Remove-VMHostAccount],[Remove-VMHostNetworkAdapter, Remove-VMHostNetworkAdapter],[Remove-VMHostNtpServer, Remove-VMHostNtpServer],[Remove-VMHostProfile, Remove-VMHostProfile],[Remove-VMHostProfileVmPortGroupConfiguration, Remove-VMHostProfileVmPortGroupConfiguration],[Remove-VMHostRoute, Remove-VMHostRoute],[Restart-VM, Restart-VM],[Restart-VMGuest, Restart-VMGuest],[Restart-VMHost, Restart-VMHost],[Restart-VMHostService, Restart-VMHostService],[Set-AdvancedSetting, Set-AdvancedSetting],[Set-AlarmDefinition, Set-AlarmDefinition],[Set-Annotation, Set-Annotation],[Set-CDDrive, Set-CDDrive],[Set-Cluster, Set-Cluster],[Set-CustomAttribute, Set-CustomAttribute],[Set-Datacenter, Set-Datacenter],[Set-Datastore, Set-Datastore],[Set-DatastoreCluster, Set-DatastoreCluster],[Set-DrsClusterGroup, Set-DrsClusterGroup],[Set-DrsRule, Set-DrsRule],[Set-DrsVMHostRule, Set-DrsVMHostRule],[Set-FloppyDrive, Set-FloppyDrive],[Set-Folder, Set-Folder],[Set-HardDisk, Set-HardDisk],[Set-IScsiHbaTarget, Set-IScsiHbaTarget],[Set-NetworkAdapter, Set-NetworkAdapter],[Set-NicTeamingPolicy, Set-NicTeamingPolicy],[Set-OSCustomizationNicMapping, Set-OSCustomizationNicMapping],[Set-OSCustomizationSpec, Set-OSCustomizationSpec],[Set-PowerCLIConfiguration, Set-PowerCLIConfiguration],[Set-ResourcePool, Set-ResourcePool],[Set-ScsiController, Set-ScsiController],[Set-ScsiLun, Set-ScsiLun],[Set-ScsiLunPath, Set-ScsiLunPath],[Set-SecurityPolicy, Set-SecurityPolicy],[Set-Snapshot, Set-Snapshot],[Set-StatInterval, Set-StatInterval],[Set-Tag, Set-Tag],[Set-TagCategory, Set-TagCategory],[Set-Template, Set-Template],[Set-VApp, Set-VApp],[Set-VIPermission, Set-VIPermission],[Set-VIRole, Set-VIRole],[Set-VirtualPortGroup, Set-VirtualPortGroup],[Set-VirtualSwitch, Set-VirtualSwitch],[Set-VM, Set-VM],[Set-VMHost, Set-VMHost],[Set-VMHostAccount, Set-VMHostAccount],[Set-VMHostAdvancedConfiguration, Set-VMHostAdvancedConfiguration],[Set-VMHostAuthentication, Set-VMHostAuthentication],[Set-VMHostDiagnosticPartition, Set-VMHostDiagnosticPartition],[Set-VMHostFirewallDefaultPolicy, Set-VMHostFirewallDefaultPolicy],[Set-VMHostFirewallException, Set-VMHostFirewallException],[Set-VMHostFirmware, Set-VMHostFirmware],[Set-VMHostHba, Set-VMHostHba],[Set-VMHostModule, Set-VMHostModule],[Set-VMHostNetwork, Set-VMHostNetwork],[Set-VMHostNetworkAdapter, Set-VMHostNetworkAdapter],[Set-VMHostProfile, Set-VMHostProfile],[Set-VMHostProfileImageCacheConfiguration, Set-VMHostProfileImageCacheConfiguration],[Set-VMHostProfileStorageDeviceConfiguration, Set-VMHostProfileStorageDeviceConfiguration],[Set-VMHostProfileUserConfiguration, Set-VMHostProfileUserConfiguration],[Set-VMHostProfileVmPortGroupConfiguration, Set-VMHostProfileVmPortGroupConfiguration],[Set-VMHostRoute, Set-VMHostRoute],[Set-VMHostService, Set-VMHostService],[Set-VMHostSnmp, Set-VMHostSnmp],[Set-VMHostStartPolicy, Set-VMHostStartPolicy],[Set-VMHostStorage, Set-VMHostStorage],[Set-VMHostSysLogServer, Set-VMHostSysLogServer],[Set-VMQuestion, Set-VMQuestion],[Set-VMResourceConfiguration, Set-VMResourceConfiguration],[Set-VMStartPolicy, Set-VMStartPolicy],[Start-VApp, Start-VApp],[Start-VM, Start-VM],[Start-VMHost, Start-VMHost],[Start-VMHostService, Start-VMHostService],[Stop-Task, Stop-Task],[Stop-VApp, Stop-VApp],[Stop-VM, Stop-VM],[Stop-VMGuest, Stop-VMGuest],[Stop-VMHost, Stop-VMHost],[Stop-VMHostService, Stop-VMHostService],[Suspend-VM, Suspend-VM],[Suspend-VMGuest, Suspend-VMGuest],[Suspend-VMHost, Suspend-VMHost],[Test-VMHostProfileCompliance, Test-VMHostProfileCompliance],[Test-VMHostSnmp, Test-VMHostSnmp],[Update-Tools, Update-Tools],[Wait-Task, Wait-Task],[Wait-Tools, Wait-Tools],[Answer-VMQuestion, Answer-VMQuestion],[Apply-DrsRecommendation, Apply-DrsRecommendation],[Apply-VMHostProfile, Apply-VMHostProfile],[Export-VM, Export-VM],[Get-ESX, Get-ESX],[Get-PowerCLIDocumentation, Get-PowerCLIDocumentation],[Get-VC, Get-VC],[Get-VIServer, Get-VIServer],[Get-VIToolkitConfiguration, Get-VIToolkitConfiguration],[Get-VIToolkitVersion, Get-VIToolkitVersion],[Set-VIToolkitConfiguration, Set-VIToolkitConfiguration],[Shutdown-VMGuest, Shutdown-VMGuest] |
| VMware.VimAutomation.HorizonView | 7.6.0.10230451 | [Connect-HVServer, Connect-HVServer],[Disconnect-HVServer, Disconnect-HVServer] |
| VMware.VimAutomation.License | 10.0.0.7893904 | [Get-LicenseDataManager, Get-LicenseDataManager] |
| VMware.VimAutomation.Nsxt | 11.0.0.10364044 | [Connect-NsxtServer, Connect-NsxtServer],[Disconnect-NsxtServer, Disconnect-NsxtServer],[Get-NsxtService, Get-NsxtService] |
| VMware.VimAutomation.Sdk | 11.0.0.10334495 | [Get-ErrorReport, Get-ErrorReport],[Get-PSVersion, Get-PSVersion],[Get-InstallPath, Get-InstallPath] |
| VMware.VimAutomation.Security | 11.0.0.10380515 | [Get-SecurityInfo, Get-SecurityInfo],[Get-VTpm, Get-VTpm],[Get-VTpmCertificate, Get-VTpmCertificate],[Get-VTpmCSR, Get-VTpmCSR],[New-VTpm, New-VTpm],[Remove-VTpm, Remove-VTpm],[Set-VTpm, Set-VTpm],[Unlock-VM, Unlock-VM] |
| VMware.VimAutomation.Srm | 10.0.0.7893900 | [Connect-SrmServer, Connect-SrmServer],[Disconnect-SrmServer, Disconnect-SrmServer] |
| VMware.VimAutomation.Storage | 11.0.0.10380343 | [Add-KeyManagementServer, Add-KeyManagementServer],[Copy-VDisk, Copy-VDisk],[Export-SpbmStoragePolicy, Export-SpbmStoragePolicy],[Get-KeyManagementServer, Get-KeyManagementServer],[Get-KmipClientCertificate, Get-KmipClientCertificate],[Get-KmsCluster, Get-KmsCluster],[Get-NfsUser, Get-NfsUser],[Get-SpbmCapability, Get-SpbmCapability],[Get-SpbmCompatibleStorage, Get-SpbmCompatibleStorage],[Get-SpbmEntityConfiguration, Get-SpbmEntityConfiguration],[Get-SpbmFaultDomain, Get-SpbmFaultDomain],[Get-SpbmPointInTimeReplica, Get-SpbmPointInTimeReplica],[Get-SpbmReplicationGroup, Get-SpbmReplicationGroup],[Get-SpbmReplicationPair, Get-SpbmReplicationPair],[Get-SpbmStoragePolicy, Get-SpbmStoragePolicy],[Get-VAIOFilter, Get-VAIOFilter],[Get-VasaProvider, Get-VasaProvider],[Get-VasaStorageArray, Get-VasaStorageArray],[Get-VDisk, Get-VDisk],[Get-VsanClusterConfiguration, Get-VsanClusterConfiguration],[Get-VsanComponent, Get-VsanComponent],[Get-VsanDisk, Get-VsanDisk],[Get-VsanDiskGroup, Get-VsanDiskGroup],[Get-VsanEvacuationPlan, Get-VsanEvacuationPlan],[Get-VsanFaultDomain, Get-VsanFaultDomain],[Get-VsanIscsiInitiatorGroup, Get-VsanIscsiInitiatorGroup],[Get-VsanIscsiInitiatorGroupTargetAssociation, Get-VsanIscsiInitiatorGroupTargetAssociation],[Get-VsanIscsiLun, Get-VsanIscsiLun],[Get-VsanIscsiTarget, Get-VsanIscsiTarget],[Get-VsanObject, Get-VsanObject],[Get-VsanResyncingComponent, Get-VsanResyncingComponent],[Get-VsanRuntimeInfo, Get-VsanRuntimeInfo],[Get-VsanSpaceUsage, Get-VsanSpaceUsage],[Get-VsanStat, Get-VsanStat],[Get-VsanView, Get-VsanView],[Import-SpbmStoragePolicy, Import-SpbmStoragePolicy],[Move-VDisk, Move-VDisk],[New-KmipClientCertificate, New-KmipClientCertificate],[New-NfsUser, New-NfsUser],[New-SpbmRule, New-SpbmRule],[New-SpbmRuleSet, New-SpbmRuleSet],[New-SpbmStoragePolicy, New-SpbmStoragePolicy],[New-VAIOFilter, New-VAIOFilter],[New-VasaProvider, New-VasaProvider],[New-VDisk, New-VDisk],[New-VsanDisk, New-VsanDisk],[New-VsanDiskGroup, New-VsanDiskGroup],[New-VsanFaultDomain, New-VsanFaultDomain],[New-VsanIscsiInitiatorGroup, New-VsanIscsiInitiatorGroup],[New-VsanIscsiInitiatorGroupTargetAssociation, New-VsanIscsiInitiatorGroupTargetAssociation],[New-VsanIscsiLun, New-VsanIscsiLun],[New-VsanIscsiTarget, New-VsanIscsiTarget],[Remove-KeyManagementServer, Remove-KeyManagementServer],[Remove-NfsUser, Remove-NfsUser],[Remove-SpbmStoragePolicy, Remove-SpbmStoragePolicy],[Remove-VAIOFilter, Remove-VAIOFilter],[Remove-VasaProvider, Remove-VasaProvider],[Remove-VDisk, Remove-VDisk],[Remove-VsanDisk, Remove-VsanDisk],[Remove-VsanDiskGroup, Remove-VsanDiskGroup],[Remove-VsanFaultDomain, Remove-VsanFaultDomain],[Remove-VsanIscsiInitiatorGroup, Remove-VsanIscsiInitiatorGroup],[Remove-VsanIscsiInitiatorGroupTargetAssociation, Remove-VsanIscsiInitiatorGroupTargetAssociation],[Remove-VsanIscsiLun, Remove-VsanIscsiLun],[Remove-VsanIscsiTarget, Remove-VsanIscsiTarget],[Repair-VsanObject, Repair-VsanObject],[Set-KeyManagementServer, Set-KeyManagementServer],[Set-KmsCluster, Set-KmsCluster],[Set-NfsUser, Set-NfsUser],[Set-SpbmEntityConfiguration, Set-SpbmEntityConfiguration],[Set-SpbmStoragePolicy, Set-SpbmStoragePolicy],[Set-VAIOFilter, Set-VAIOFilter],[Set-VDisk, Set-VDisk],[Set-VsanClusterConfiguration, Set-VsanClusterConfiguration],[Set-VsanFaultDomain, Set-VsanFaultDomain],[Set-VsanIscsiInitiatorGroup, Set-VsanIscsiInitiatorGroup],[Set-VsanIscsiLun, Set-VsanIscsiLun],[Set-VsanIscsiTarget, Set-VsanIscsiTarget],[Start-SpbmReplicationFailover, Start-SpbmReplicationFailover],[Start-SpbmReplicationPrepareFailover, Start-SpbmReplicationPrepareFailover],[Start-SpbmReplicationPromote, Start-SpbmReplicationPromote],[Start-SpbmReplicationReverse, Start-SpbmReplicationReverse],[Start-SpbmReplicationTestFailover, Start-SpbmReplicationTestFailover],[Start-VsanClusterDiskUpdate, Start-VsanClusterDiskUpdate],[Start-VsanClusterRebalance, Start-VsanClusterRebalance],[Start-VsanEncryptionConfiguration, Start-VsanEncryptionConfiguration],[Stop-SpbmReplicationTestFailover, Stop-SpbmReplicationTestFailover],[Stop-VsanClusterRebalance, Stop-VsanClusterRebalance],[Sync-SpbmReplicationGroup, Sync-SpbmReplicationGroup],[Test-VsanClusterHealth, Test-VsanClusterHealth],[Test-VsanNetworkPerformance, Test-VsanNetworkPerformance],[Test-VsanStoragePerformance, Test-VsanStoragePerformance],[Test-VsanVMCreation, Test-VsanVMCreation],[Update-VsanHclDatabase, Update-VsanHclDatabase] |
| VMware.VimAutomation.StorageUtility | 1.3.0.0 | [Update-VmfsDatastore, Update-VmfsDatastore] |
| VMware.VimAutomation.Vds | 11.0.0.10336077 | [Add-VDSwitchPhysicalNetworkAdapter, Add-VDSwitchPhysicalNetworkAdapter],[Add-VDSwitchVMHost, Add-VDSwitchVMHost],[Export-VDPortGroup, Export-VDPortGroup],[Export-VDSwitch, Export-VDSwitch],[Get-VDBlockedPolicy, Get-VDBlockedPolicy],[Get-VDPort, Get-VDPort],[Get-VDPortgroup, Get-VDPortgroup],[Get-VDPortgroupOverridePolicy, Get-VDPortgroupOverridePolicy],[Get-VDSecurityPolicy, Get-VDSecurityPolicy],[Get-VDSwitch, Get-VDSwitch],[Get-VDSwitchPrivateVlan, Get-VDSwitchPrivateVlan],[Get-VDTrafficShapingPolicy, Get-VDTrafficShapingPolicy],[Get-VDUplinkLacpPolicy, Get-VDUplinkLacpPolicy],[Get-VDUplinkTeamingPolicy, Get-VDUplinkTeamingPolicy],[New-VDPortgroup, New-VDPortgroup],[New-VDSwitch, New-VDSwitch],[New-VDSwitchPrivateVlan, New-VDSwitchPrivateVlan],[Remove-VDPortGroup, Remove-VDPortGroup],[Remove-VDSwitch, Remove-VDSwitch],[Remove-VDSwitchPhysicalNetworkAdapter, Remove-VDSwitchPhysicalNetworkAdapter],[Remove-VDSwitchPrivateVlan, Remove-VDSwitchPrivateVlan],[Remove-VDSwitchVMHost, Remove-VDSwitchVMHost],[Set-VDBlockedPolicy, Set-VDBlockedPolicy],[Set-VDPort, Set-VDPort],[Set-VDPortgroup, Set-VDPortgroup],[Set-VDPortgroupOverridePolicy, Set-VDPortgroupOverridePolicy],[Set-VDSecurityPolicy, Set-VDSecurityPolicy],[Set-VDSwitch, Set-VDSwitch],[Set-VDTrafficShapingPolicy, Set-VDTrafficShapingPolicy],[Set-VDUplinkLacpPolicy, Set-VDUplinkLacpPolicy],[Set-VDUplinkTeamingPolicy, Set-VDUplinkTeamingPolicy],[Set-VDVlanConfiguration, Set-VDVlanConfiguration] |
| VMware.VimAutomation.Vmc | 11.0.0.10336076 | [Connect-Vmc, Connect-Vmc],[Disconnect-Vmc, Disconnect-Vmc],[Get-VmcSddcNetworkService, Get-VmcSddcNetworkService],[Get-VmcService, Get-VmcService],[Connect-VmcServer, Connect-VmcServer],[Disconnect-VmcServer, Disconnect-VmcServer] |
| VMware.VimAutomation.vROps | 10.0.0.7893921 | [Connect-OMServer, Connect-OMServer],[Disconnect-OMServer, Disconnect-OMServer],[Get-OMAlert, Get-OMAlert],[Get-OMAlertDefinition, Get-OMAlertDefinition],[Get-OMAlertSubType, Get-OMAlertSubType],[Get-OMAlertType, Get-OMAlertType],[Get-OMRecommendation, Get-OMRecommendation],[Get-OMResource, Get-OMResource],[Get-OMStat, Get-OMStat],[Get-OMStatKey, Get-OMStatKey],[Get-OMUser, Get-OMUser],[Set-OMAlert, Set-OMAlert] |
| VMware.VumAutomation | 6.5.1.7862888 | [Add-EntityBaseline, Add-EntityBaseline],[Copy-Patch, Copy-Patch],[Get-Baseline, Get-Baseline],[Get-Compliance, Get-Compliance],[Get-Patch, Get-Patch],[Get-PatchBaseline, Get-PatchBaseline],[New-PatchBaseline, New-PatchBaseline],[Remove-Baseline, Remove-Baseline],[Remove-EntityBaseline, Remove-EntityBaseline],[Set-PatchBaseline, Set-PatchBaseline],[Sync-Patch, Sync-Patch],[Test-Compliance, Test-Compliance],[Update-Entity, Update-Entity],[Attach-Baseline, Attach-Baseline],[Detach-Baseline, Detach-Baseline],[Download-Patch, Download-Patch],[Remediate-Inventory, Remediate-Inventory],[Scan-Inventory, Scan-Inventory],[Stage-Patch, Stage-Patch] |
```

### 証明書設定を変更
これを事前に実行しとかないとvCenterへの接続が失敗しちゃいます。

```
> Set-PowerCLIConfiguration -InvalidCertificateAction Ignore
```

### vCenter(ESXi)接続
```
> Connect-VIServer -Server IPアドレス -User root -Password password

Name                           Port  User
----                           ----  ----
xx.xx.xx.xx                     443   root
```

### VM情報を取得

* 起動しているVMを対象に
* VM名
* IPアドレス
* ホスト(ESXi)
* データストア

を抽出して出力してみます。

```
get-vm | 
where { $_.PowerState -eq "PoweredOn" } | 
select Name,
@{N="IPAddress";E={$_.Guest.IpAddress}},
VMHost,
@{N="Datastore";E={[string]::Join(',',(Get-Datastore -Id $_.DatastoreIdList | select -ExpandProperty Name))}} | 
sort-object Name

Name             IPAddress                                                 VMHost      Datastore
----             ---------                                                 ------      ---------
XxxxxVPNClient   xxx.xx.xx.xx                                             xx-xxx-01_01
・
・
<中略>
・
・
xxxx             xxx.xx.xxx.x                                              xx-xxx-01_01

```

PowerCLIを実行して標準出力をWSL側のコマンドで整形したりしてみます。

```
$ pwsh -c "Get-Command | Select-object Name,Version" | grep ^Get*
Get-DeployCommand                               6.7.0.8250345
Get-ESX                                         11.0.0.10336080
Get-PIAccessControlRule                         11.0.0.10379994
Get-PINetworkAdapter                            11.0.0.10379994
Get-PIUser                                      11.0.0.10379994
```

PowerShell側のパイプはダブルクォーテーションとかで囲むと良さそうです。