I am trying to pass a string as a filename to a function. This happens with everything, I am just using vmware powercli as a example. Why am I getting this error:
Here is my powershell code? (Sorry this has been stumping me for hours):
PowerCLI C:\> $BackupDir
c:\temp
PowerCLI C:\> $backupDate
20181225
PowerCLI C:\> $line
myVM
PowerCLI C:\> $ovafilename = $line+"_v"+$backupDate+".ova"
myVM v20181212.ova
......................
......................
......................
... And now here is the problem command. It wont convert my string to a instance object:
PowerCLI C:\> Export-VApp -Destination $BackupDir -VM $line -Format OVA -Name $ovafilename
And this error message appears:
Export-VApp : 12/25/2018 11:20:11 AM Export-VApp Object reference not set to an instance of an object.
At line:1 char:1
+ Export-VApp -Destination $BackupDir -VM $line -Format OVA -Name "$ova ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Export-VApp], ViError
+ FullyQualifiedErrorId : Client20_NfcLease_RunNfcTask_Error,VMware.VimAutomation.ViCore.Cmdlets.Commands.ExportVApp
However......... if I replace the $ovafilename string, and type it manually it works. Why is this?
PowerCLI C:\> Export-VApp -Destination $BackupDir -VM $line -Format OVA -Name "testfilename.ova"
So PowerCLI export-vapp doesnt accept a filename with ( ) or [ ], and so i had i had to replace it with a _ underscrore to fix it