VMware PowerCLI: default settings and log4net fix
PowerCLI configuration, credential store authentication and the 64-bit log4net fix.
A few common settings and fixes for using VMware PowerCLI from PowerShell.
Default configuration
Import-Module VMware.PowerCLI
# Do not participate in the Customer Experience Improvement Program
Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $false
# Allow several simultaneous connections to vCenter/ESXi servers
Set-PowerCLIConfiguration -DefaultVIServerMode multiple -Confirm:$false
Integrated authentication issue
If Windows integrated authentication fails, you can store credentials in a PowerCLI credential store file and read them back to connect (see this article):
New-VICredentialStoreItem -User domain\username -Password '<PASSWORD>' -Host vcenter01 -File C:\Temp\vicreds.xml
$logon = Get-ViCredentialStoreItem -File C:\Temp\vicreds.xml
Connect-VIServer -Server $logon.Host -User $logon.User -Password $logon.Password
64-bit log4net error
After installing the module, the import can fail because the log4net assembly is missing from the 64-bit GAC. The fix is to copy log4net.dll, shipped with the VMware.VimAutomation.Sdk module, into the 64-bit GAC folder:
# Target folder in the 64-bit GAC (replace <version> with the log4net version shipped with the module)
$newDir = "C:\Windows\assembly\GAC_64\log4net\<version>__692fbea5521e1304"
New-Item $newDir -ItemType directory -Force
$file = Get-ChildItem "C:\Program Files\WindowsPowerShell\Modules\VMware.VimAutomation.Sdk" |
Select-Object -Last 1 |
Get-ChildItem -Recurse -Filter "log4net.dll" |
Select-Object -First 1
Copy-Item $file.FullName $newDir
# Verify the copy
Get-ChildItem $newDir
Then close all instances of VS Code, PowerShell ISE and PowerShell consoles, open a 64-bit PowerShell console and run Import-Module VMware.PowerCLI.
Notes
- Storing a password in a file is not very safe: restrict the file permissions or prefer a secret vault.