Powershell 问题:对象实例的字符串用作 export-vapp 的文件名

Powershell question: String to Instance of an Object to use as a filename for export-vapp

我正在尝试将字符串作为文件名传递给函数。一切都会发生这种情况,我只是以 vmware powercli 为例。为什么会出现此错误:

这是我的 powershell 代码? (抱歉,这已经困扰了我几个小时):

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

并出现此错误消息:

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

但是.........如果我替换 $ovafilename 字符串并手动输入它,它就可以工作。这是为什么?

PowerCLI C:\> Export-VApp -Destination $BackupDir -VM $line -Format OVA -Name "testfilename.ova"

所以 PowerCLI export-vapp 不接受带有 ( ) 或 [ ] 的文件名,所以我不得不用 _ 下划线替换它来修复它