Export-VApp command in powershell is not accepting a VM with space in the VM Name

Ravindra Shukla 116 Reputation points
2021-09-07T10:08:28.083+00:00

Hello,

I am working on a POC for exporting a VM using "Export-VApp" command in powershell script. My script is working fine for the VMs

However some of my VMs are having a "blank space" in their name like "Windows 10 Test VM" and the Export-VApp command is not working for this scenarios and giving an error.

Could you please help me to know how I can pass VM Name with space in it to Export-VApp command ?

Also is there any dry-run kind of option for Export-VApp command to check without actually starting the VM export process, please let me know.

Thanks

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,381 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Limitless Technology 39,371 Reputation points
    2021-09-07T15:33:55.323+00:00

    Hello @Ravindra Shukla

    I would like to suggest you to use double quote if there is space in VM name.
    also , you can use What-If parameter which will show only what is going to change for your dry-run.

    If the reply was helpful, please don’t forget to upvote or accept as answer.

    0 comments No comments

  2. Rich Matheisen 45,091 Reputation points
    2021-09-07T17:25:59.163+00:00

    If you're not doing so already, place the VM name in a variable and use the variable in place of the string on the cmdlet, or place the name of the VM in quotation marks when using it.

    $vmname = 'abc def'
    export-vapp -name $vmname

    or:

    export-vapp -name "abc def"

    You can add the "-WhatIf" switch to the export-vapp cmdlet to test.

    0 comments No comments

  3. Ravindra Shukla 116 Reputation points
    2021-09-08T08:04:07.527+00:00

    Hi @Limitless Technology and @Rich Matheisen

    Thank you for your reply.

    I tried using the double quotes for the VM name and also tried using the variable, but for me, its not working.

    Export-VApp is giving me below error -

    PS C:\> Get-VM -Name "Windows 10_ltsc_test_01" | Export-VApp -Destination $downloadPath -Format OVA -force  
    Export-VApp : 9/8/2021 1:24:59 PM       Export-VApp             Object reference not set to an instance of an object.  
    At line:1 char:42  
    + ... _test_01" | Export-VApp -Destination $downloadPath -Format OVA -force ...  
    +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
        + CategoryInfo          : NotSpecified: (:) [Export-VApp], ViError  
        + FullyQualifiedErrorId : Client20_NfcLease_RunNfcTask_Error,VMware.VimAutomation.ViCore.Cmdlets.Commands.ExportVApp  
    
    
    
    PS C:\> Export-VApp -VM "Windows 10_ltsc_test_01" -Destination $downloadPath -Format OVA -force  
    Export-VApp : 9/8/2021 1:31:10 PM       Export-VApp             Object reference not set to an instance of an object.  
    At line:1 char:1  
    + Export-VApp -VM "Windows 10_ltsc_test_01" -Destination $downloadPath  ...  
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
        + CategoryInfo          : NotSpecified: (:) [Export-VApp], ViError  
        + FullyQualifiedErrorId : Client20_NfcLease_RunNfcTask_Error,VMware.VimAutomation.ViCore.Cmdlets.Commands.ExportVApp  
    

    Please suggest if I am doing anything wrong.

    0 comments No comments