PowerCLI

 View Only
  • 1.  New-VM Cmdlet & Network Locations

    Posted Nov 14, 2022 06:35 PM

    Hey all,

    I've got a really weird issue. I've written a small script for my team to automate the build out of our VMs. However, whenever it gets to the point in the script that has the `New-VM` cmdlet, it will error out with the following error:

    New-VM : 11/14/2022 12:23:59 PM New-VM          Cannot find path '\\domain' because it does not exist.
    At \\domain\datadfs\SysAdmin\Scripts\New-Server\New-Server.ps1:594 char:18
    + ... cloneTask = New-VM -ResourcePool $cluster -Datastore $datastore -Name ...
    +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [New-VM], VimException
        + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM

      The relevant part of the script is this

    $cloneTask = New-VM -ResourcePool $cluster -Datastore $datastore -Name $server -Template $template -Location $folder -OSCustomizationSpec 'Default OSCustomizationSpec' -RunAsync

    My team runs the script from Powershell using the network location, for example "\\domain\datadfs\SysAdmin\Scripts\New-Server\New-Server.ps1". The error also occurs if the FQDN is used. The only time I don't get the error is if I map the network location as a local drive and run it from there. Does anyone know if this is a PowerCLI limitation or am I doing something wrong?



  • 2.  RE: New-VM Cmdlet & Network Locations

    Posted Nov 14, 2022 07:06 PM

    This is not an exclusive PowerCLI issue, but a general PowerShell issue.
    Running scripts from a network drive often shows this "Cannot find path ..." message.

    The best solution is to indeed run from a local drive.
    Map that UNC via a New-PSProvider to a local drive.

    You could also try playing with the ExecutionPolicy by setting it to 'Unrestricted'.
    But I strongly advise against doing that!



  • 3.  RE: New-VM Cmdlet & Network Locations

    Posted Nov 14, 2022 07:11 PM

    It does work from the network drive, just not the UNC network location. Would you recommend mapping the UNC inside the script in that case?



  • 4.  RE: New-VM Cmdlet & Network Locations

    Posted Nov 14, 2022 07:18 PM

    Not sure I understand that last remark?
    If you map the network location, i.e. assign a drive letter, it is considered a local drive.
    Only when you start a PS script with the UNC path that error appears.



  • 5.  RE: New-VM Cmdlet & Network Locations

    Posted Nov 14, 2022 07:22 PM

    You are correct, my last remark was in response to "Map that UNC via a New-PSProvider to a local drive."