werwef
Contributor
Contributor

New-VM Cmdlet & Network Locations

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?

0 Kudos
4 Replies
LucD
Leadership
Leadership

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!


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
werwef
Contributor
Contributor

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?

0 Kudos
LucD
Leadership
Leadership

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.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
werwef
Contributor
Contributor

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

0 Kudos