Scripting new VHDx using PowerShell

Associate
Joined
7 Aug 2012
Posts
948
Scripting new VHDx using PowerShell [Resolved]

Hi All,

Got a bit of an issue when I'm trying to script the creation of a new VHDx.

If I open Powershell and send/type the following command it creates a new VHDx file;
Code:
NEW-VHD -Fixed -SizeBytes 2GB -path "E:\Virtual Machine VHDs\Test.vhdx"

However if I try passing the parameters by using the run command using this;

Code:
powershell NEW-VHD -Fixed -SizeBytes 2GB -path "E:\Virtual Machine VHDs\Test.vhdx"

I get this error;

Code:
New-VHD : A positional parameter cannot be found that accepts argument 'Machine'.

At line:1 char:1

+ NEW-VHD -Fixed -SizeBytes 2GB -path E:\Virtual Machine VHDs\Test.vhdx

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (:) [New-VHD], ParameterBindingException

    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.Vhd.PowerShell.NewVhdCommand

However if I use the run command with this;

Code:
powershell New-VHD -Fixed -SizeBytes 2GB –Path E:\NewVHDFile.VHDX

it then works.

I can only assume it's something to do with spaces between my directory but I've tried playing about with quotes and no luck!

Cheers Swain90
 
Last edited:
Associate
OP
Joined
7 Aug 2012
Posts
948
Using this from the run command has resolved the problem

Code:
powershell NEW-VHD -Fixed -SizeBytes 2GB -path 'E:\Virtual Machine VHDs\Test.vhdx'

I have no idea why M$ have swapped to using single quotes for this function !?
 
Back
Top Bottom