none
Exporting Select VM's RRS feed

  • Question

  • I'm trying to Export a few VM's but removing OLD folder

    The VM's that need exporting change & I don't want to export All & to avoid errors by others I'm naming the VM's and assinging to a variable.

    If I had code it ie. Remove-Item -Path F:\xPort\Apps1  -Force -Recurse -Confirm:$False

    it works ok

    The problem sis with the Remove-Item line

    $outfile ="F:\Utils\logs\vmXport.txt"
    $Export  ="F:\xPort\"
    $vmName1  ="Apps1"
    $vmName2  ="Apps2"

    #Remove last
    Remove-Item -Path $Export\$vmName1 -Force -Recurse -Confirm:$False
    Remove-Item -Path $Export\$vmName2 -Force -Recurse -Confirm:$False

    $start = Get-Date
    Export-VM -name $vmName1 -path $Export
    $end   = Get-Date
    add-content $outfile "Start $start"
    add-content $outfile "Finished $end"

    Export-VM -name $vmName2 -path $Export
    $end   = Get-Date
    add-content $outfile "Start $start"
    add-content $outfile "Finished $end"

    I receive an error:

       + CategoryInfo          : ObjectNotFound: (F:\xPort\Apps1:String) [Remove-Item], ItemNotFoundException

    Not sure where the Apps1:String is coming from !


    ChrisS


    • Edited by ChrisS - ITR Sunday, November 24, 2019 1:35 PM correction
    Sunday, November 24, 2019 1:34 PM

All replies

  • If you're "building" paths you should use Join-Path. That's less error prone than sticking it together in the wrong way. ;-)  Please read the complete help  including the examples to learn how to use it.

    Hint: Using " $Export\$vmName1" to build a path from this "F:\xPort\" and this "Apps1" does not result in what you expect it to be ... probably.  ;-)


    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    • Edited by BOfH-666 Sunday, November 24, 2019 2:20 PM
    Sunday, November 24, 2019 2:19 PM