Hi all,
Could use some help with my script. Here's the snippet that's having problems:
#Import VMware commands
Import-Module Vmware.VimAutomation.Vds
#Get Timestamp
$Timestamp = (Get-Date -Format "yyyy-MM-dd")
#Build array for vCenters
$vCenter = "vcenter", "vcenter2", "venter3", "vcenter4"
#Connect to vCenter server
connect-viserver $vCenter[0]
#Add the vSwitches to an array
$VDSArray = get-vdswitch
Back up each vDS switch to timestamped folder
foreach ($VDSwitch in $VDSArray)
{
get-vdswitch -Name $VDSwitch| export-vdswitch -Description "vCenter vDS Switch" -Destination ("E:\ScriptsOutput\BackupDVS\$Timestamp\" + $vCenter[0] + "_" + $VDSwitch + ".zip") -Force
}
#Disconnect from vCenter
disconnect-viserver $vCenter[0] -confirm:$false
Where it's all falling apart is at the "export-vdswitch", error below:
export-vdswitch : 9/27/2017 8:28:59 AM Export-VDSwitch The method is not supported in the API version 5.5.
At line:32 char:1
+ export-vdswitch $switch -Withoutportgroups -Description "Backup of $switch witho ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Export-VDSwitch], ViError
+ FullyQualifiedErrorId : Vds_Impl_VDSwitchServiceImpl_ExportVDSwitch_Error,VMware.VimAutomation.Vds.Commands.ExportVDSwitch
So I did some research on this error, all the other discussions told me to run a "Get-PSSnapin|ft -a" and see what it lists :
C:\> Get-PSSnapin|ft -a
Name PSVersion Description
---- --------- -----------
Microsoft.PowerShell.Core 3.0 This Windows PowerShell snap-in contains cmdlets used to manage components of Windows PowerShell.
VMware.VimAutomation.Core 3.0 This Windows PowerShell snap-in contains Windows PowerShell cmdlets for managing vSphere.
VMware.DeployAutomation 3.0 This Windows Powershell snap-in contains vSphere Auto Deploy related cmdlets for Rule-Based-Deployment
VMware.ImageBuilder 3.0 This Windows PowerShell snap-in contains VMware ESXi Image Builder cmdlets used to generate custom images.
As you can see it doesn't contain the following PSSnapin's: "VMware.VimAutomation.Vds, VMware.VumAutomation, VMware.VimAutomation.License" as is recommended in all the other troubleshooting discussions I've seen. Solution to that is supposed to be "Add-PSSnapin VMware.$x" but whenever I try that I get the following error:
C:\> Add-PSSnapin VMware.VimAutomation.Vds
Add-PSSnapin : The Windows PowerShell snap-in 'VMware.VimAutomation.Vds' is not installed on this computer.
At line:1 char:1
+ Add-PSSnapin VMware.VimAutomation.Vds
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (VMware.VimAutomation.Vds:String) [Add-PSSnapin], PSArgumentException
+ FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand
So that's where my dead-end is. If anyone could talk me through the issues I'm having it would be greatly appreciated.
Thanks!
You'll require at least v4, I advise to go for v5.1
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Let's try to determine which PowerCLI version you have installed.
Can you do the following?
Get-PSSnapin -Name VMware* -Registered
Get-Module -Name VMware* -ListAvailable
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for responding!
C:\> Get-PSSnapin -Name VMware* -Registered
Name : VMware.DeployAutomation
PSVersion : 3.0
Description : This Windows Powershell snap-in contains vSphere Auto Deploy related cmdlets for Rule-Based-Deployment
Name : VMware.ImageBuilder
PSVersion : 3.0
Description : This Windows PowerShell snap-in contains VMware ESXi Image Builder cmdlets used to generate custom images.
Name : VMware.VimAutomation.Core
PSVersion : 3.0
Description : This Windows PowerShell snap-in contains Windows PowerShell cmdlets for managing vSphere.
and
C:\> Get-Module -Name VMware* -ListAvailable
Directory: C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Modules
ModuleType Name ExportedCommands ---------- ---- ----------------
Binary VMware.VimAutomation.Cis.Core
Binary VMware.VimAutomation.Cloud
Manifest VMware.VimAutomation.Common Manifest VMware.VimAutomation.Core
Binary VMware.VimAutomation.HA
Binary VMware.VimAutomation.License
Binary VMware.VimAutomation.PCloud
Manifest VMware.VimAutomation.SDK
Binary VMware.VimAutomation.Storage
Binary VMware.VimAutomation.Vds
Binary VMware.VimAutomation.vROps
Binary VMware.VumAutomation
Looks like you are on a pre-PowerCLI 6.5R1 release.
Those were a mix of PSSnapin and Modules.
Try loading these with the following, and then try your script again.
Get-PSSnapin -Name VMware* -Registered | Add-PSSnapin
Get-Module -Name VMware* -ListAvailable | Import-Module
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Nope, same error. Still lists the stunted version of the PSSnapin's with a ft -a. Still can't add new snapins. Do I need to upgrade my powerCLI?
That would be the best choice.
See the instructions in Updating PowerCLI through the PowerShell Gallery
Currently POwerCLI is at 6.5.2, but those instructions will work.
Make sure to uninstall any older versions before doing the Install-Module
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Sigh. I can't even follow the guide because apparently my PowerShell doesn't even have an "Update-Module" function. Guess I have a ton of Powershell bugs to work out. Thanks for the help!
Which PowerShell version are you using, you can check by displaying $PSVersionTable
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
C:\> $PSVersionTable
Name Value
---- -----
PSVersion 3.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.42000
BuildVersion 6.2.9200.22198
PSCompatibleVersions {1.0, 2.0, 3.0}
PSRemotingProtocolVersion 2.2
You'll require at least v4, I advise to go for v5.1
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Upgrading fixed it!