我正在尝试将字符串作为文件名传递给函数。这一切都会发生,我只是以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"
答案 0 :(得分:0)
因此PowerCLI export-vapp不接受带有()或[]的文件名,因此我不得不用_下划线替换它来修复它