Unable to connect VMware Cloud director 10.4 through PowerCLI

While attempting to connect to VMware Cloud Director 10.4 using PowerCLI, I encountered the error message “The server returned the following: NotAcceptable: ”.”

 PS C:\Users\sreejesh> Connect-CIServer -Server vcd.sreejesh.lab -Credential (Get-Credential)
Connect-CIServer : 3/27/2023 8:01:29 AM	Connect-CIServer		Unable to connect to vCloud Server 'https://vcd.sreejesh.lab:443/api/'. The server returned the following: NotAcceptable: ''.	
At line:1 char:1
+ Connect-CIServer -Server https://vcd.sreejesh.lab  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Connect-CIServer], CIException
    + FullyQualifiedErrorId : Cloud_ConnectivityServiceImpl_ConnectCloudServer_ConnectError,VMware.VimAutomation.Cloud.Commands.Cmdlets.ConnectCIServer 

This issue is a known limitation with PowerCLI versions prior to 13.0. The error occurs because PowerCLI versions earlier than 13.0.0 do not support VMware Cloud Director API versions greater than 33.0. To resolve this issue, the solution is to install the latest version of PowerCLI, version 13.0. If encountering this issue, first confirm that the current PowerCLI version is less than 13.0, and if so, uninstall and reinstall with the latest version to resolve the issue.

 
PS C:\Users\sreejesh> Get-PowerCLIVersion
WARNING: The cmdlet "Get-PowerCLIVersion" is deprecated. Please use the 'Get-Module' cmdlet instead.

PowerCLI Version
----------------
   VMware.PowerCLI 12.7.0 build 20091289
---------------
Component Versions
---------------
   VMware Common PowerCLI Component 12.7 build 20067789
   VMware Cis Core PowerCLI Component PowerCLI Component 12.6 build 19601368
   VMware VimAutomation VICore Commands PowerCLI Component PowerCLI Component 12.7 build 20091293
   VMware VimAutomation Storage PowerCLI Component PowerCLI Component 12.7 build 20091292
   VMware VimAutomation Vds Commands PowerCLI Component PowerCLI Component 12.7 build 20091295
   VMware VimAutomation Cloud PowerCLI Component PowerCLI Component 12.0 build 15940183 


PS C:\Users\sreejesh> Remove-Module -Name VMware.PowerCLI -Force
PS C:\Users\sreejesh> Install-Module -Name VMware.PowerCLI 

PS C:\Users\sreejesh> Get-PowerCLIVersion

PowerCLI Version
----------------
   VMware.VimAutomation.Core 13.0.0 build 20797821
---------------
Component Versions
---------------
   VMware Common PowerCLI Component 13.0 build 20797081
   VMware Cis Core PowerCLI Component PowerCLI Component 13.0 build 20797636
   VMware VimAutomation VICore Commands PowerCLI Component PowerCLI Component 13.0 build 20797821

PowerCLI to deploy VMs in VMware vCloud and connect to network

vCloud PowerCLI

This PowerCLI script will help you to deploy VMs in VMware Private vCloud and connect to network.

 
 
#############################
# Deploy VMs in  vCloud     #
#############################
# Change Log
# 1.0 This script will Create vApp and deploy VMs from the selected TemplateVM.
 
################
# INITIALIZING #
################
 
### DECLARING VARIABLES ###
 
$vCloud_Server = "vCloud Server" # vCloud Server FQDN
$vCloud_Org    =    "Org Name"   # Org Name
$orgNetwork = "orgNwName"        # Target OrgNetworkName for the VM.
$templateVM = "TemplateVMName    # Template VM Name.
$vmCount = 2                     # No of VMs required.
$vmIndex = 4                     # VM starting index.
$vAppNamePrefix =  "RHEL-vApp"   # Prefix string in the vApp Name.
$VMNamePrefix = "RHEL-VM"        # Prefix string in the VM Name.
 
### Connect to the vCloud Server ###
Connect-CIServer $vCloud_Server
 
### Deploying VMs ###
$vmCount = $vmIndex + $vmCount
 
for($i=$vmIndex; $i -le $vmCount; $i++)
{
$vAppName = $vAppNamePrefix+"$i"
$VMName = $VMNamePrefix+"$i"
 
### Creating new vApp ###
New-CIVApp -Name $vAppName -OrgVdc $vCloud_Org
 
### Deploy the VM from template inside the newly created vApp###
New-CIVM -Name "$VMName" -VMTemplate $templateVM -VApp $vAppName -ComputerName "$VMName"
 
### Creating new vApp Network ###
New-CIVAppNetwork -VApp $vAppName -Direct -ParentOrgNetwork $orgNetwork
 
$vAppNetwork = get-civapp $vAppName | Get-CIVAppNetwork $orgNetwork
$cldVMs = get-civapp $vAppName | get-civm
 
### Connecting the vNIC to the network ###
### Please change the allocation model if required###
foreach ($cldvm in $cldVMs) {
    $cldvm | Get-CINetworkAdapter | Set-CINetworkAdapter -vappnetwork $vAppNetwork -IPaddressAllocationMode Pool -Connected $True
}
### Powering on the vApp ###
get-CIVApp -Name $vAppName | Start-CIVApp
}
 
Disconnect-CIServer $vCloud_Server -Force -Confirm:$false
 

 

PowerCLI script to Set Perennial reservation on RDM LUNs in a Cluster

Please find the Powercli script for configuring Perennial reservation on all RDM luns in a ESXi Cluster. Please change the value for following variables before you execute the script.

$vcenter = “vCenter.vmtest.com”
$dCenter = “123456”
$cluster = “Production Hypervisor”

This is the flow of script execution.

1. Get the list of RDM LUNs from the cluster.
2. Check the current perennial reservation status of the RDM. If it’s TRUE, no changes will be applied.
3. If the status is FALSE, the perennial reservation will be set on the LUN.
4. Script will query the latest status and the status will be displayed.

The result, after executing the script, looks something like this.

perinnial reservation

 

 

 

# This script will set the parameter Perennially Reservations to True on RDM Luns in a cluster
#$vcenter = #"vCenter Name "
#$dCenter = #"Datacenter Name"
#$cluster = #"Cluster Name"

$vcenter = "vCenter.vmtest.com"
$dCenter = "123456"
$cluster = "Production Hypervisor"

#-------------------------------------------------------------------------

# Do not modify bellow script
#-------------------------------------------------------------------------

#Add-PSSnapIn VMware* -ErrorAction SilentlyContinue

$connected = Connect-VIServer -Server $vcenter | Out-Null

$clusterInfo = Get-Datacenter -Name $dCenter | get-cluster $cluster
$vmHosts = $clusterInfo | get-vmhost | select -ExpandProperty Name
$RDMNAAs = $clusterInfo | Get-VM | Get-HardDisk -DiskType "RawPhysical","RawVirtual" | Select -ExpandProperty ScsiCanonicalName -Unique

foreach ($vmhost in $vmHosts) {
$myesxcli = Get-EsxCli -VMHost $vmhost

foreach ($naa in $RDMNAAs) {

$diskinfo = $myesxcli.storage.core.device.list("$naa") | Select -ExpandProperty IsPerenniallyReserved
$vmhost + " " + $naa + " " + "IsPerenniallyReserved= " + $diskinfo
if($diskinfo -eq "false")
{
write-host "Configuring Perennial Reservation for LUN $naa......."
$myesxcli.storage.core.device.setconfig($false,$naa,$true)
$diskinfo = $myesxcli.storage.core.device.list("$naa") | Select -ExpandProperty IsPerenniallyReserved
$vmhost + " " + $naa + " " + "IsPerenniallyReserved= " + $diskinfo
}
write-host "----------------------------------------------------------------------------------------------"
}
}

Disconnect-VIServer $vcenter -confirm:$false | Out-Null

PowerCLI sccript for exporting VM details to HTML

Its a simple script for exporting VM details to HTML format. The HTML report created will be saved into the folder with the name of current month. It will help in generating a daily report with the help of Windows Task Scheduler. Refer this article for scheduling PowerCLI script.

Following details will be collected.

1. No of VMs in the vCenter.
2. No of Hosts connected in vCenter.
3. PowerState of VMs, IP address, Base ESX host, Cluster Name.
Continue reading