VMware Cloud Community
GrantOrchardVMw
Commander
Commander
Jump to solution

Multiple VMs and Get-OSCustomizationNicMapping (again)

Hey guys,

I'm putting together a script to create multiple vms from a csv list. I know it's been done before, but I learn more when I work through it myself.

I've put together the script below, which provisions the VM just fine, but fails at Get-OSCustomizationNicMapping.

Here's the script:

Import-CSV "d:\vmlist.csv" | ForEach-Object {
    New-VM -Name $_.Name -Template "Microsoft Windows 2003 R2 Standard x86" -VMHost $_.VMHost `
    -Location $_.Location -Datastore $_.Datastore -diskstorageformat Thin `
    -OSCustomizationSpec "Microsoft Windows 2003 R2 Standard x86" `
    | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping `
    -IPAddress $_.IPAddress -SubnetMask $_.SubnetMask -DefaultGateway $_.DefaultGateway `
    -DNS $_.DNS
}

and the error I'm receiving:

Get-OSCustomizationNicMapping : The input object cannot be bound to any paramet
ers for the command either because the command does not take pipeline input or
the input and its properties do not match any of the parameters that take pipeline input.
At line:5 char:36
+     | Get-OSCustomizationNicMapping <<<<  | Set-OSCustomizationNicMapping `
    + CategoryInfo          : InvalidArgument: (vmname:PSObject) [Get-O
   SCustomizationNicMapping], ParameterBindingException
    + FullyQualifiedErrorId : InputObjectNotBound,VMware.VimAutomation.ViCore.
   Cmdlets.Commands.GetOSCustomizationNicMapping

Maybe I'm misunderstanding the usage of Get-OSCustomizationNicMapping.

Thanks for your help,

Grant

Grant http://grantorchard.com
0 Kudos
1 Solution

Accepted Solutions
admin
Immortal
Immortal
Jump to solution

Hi Grant,

The cause of the problem is that you are piping the output of New-VM (which is VirtualMachine) to Get-OSCustomizationNicMapping. You need to pass an OSCustomizationSpec to the cmdlet. You'll need to update the nic mapping of the customization spec before you pass the spec as a parameter to New-VM. Here's an example:

Get-OSCustomizationSpec -Name "Microsoft Windows 2003 R2 Standard x86" | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IPAddress $_.IPAddress -SubnetMask $_.SubnetMask -DefaultGateway $_.DefaultGateway -DNS $_.DNS

New-VM -Name $_.Name -Template "Microsoft Windows 2003 R2 Standard x86" -VMHost $_.VMHost -Location $_.Location -Datastore $_.Datastore -diskstorageformat Thin -OSCustomizationSpec "Microsoft Windows 2003 R2 Standard x86"

Regards,

Dimitar

View solution in original post

0 Kudos
2 Replies
admin
Immortal
Immortal
Jump to solution

Hi Grant,

The cause of the problem is that you are piping the output of New-VM (which is VirtualMachine) to Get-OSCustomizationNicMapping. You need to pass an OSCustomizationSpec to the cmdlet. You'll need to update the nic mapping of the customization spec before you pass the spec as a parameter to New-VM. Here's an example:

Get-OSCustomizationSpec -Name "Microsoft Windows 2003 R2 Standard x86" | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IPAddress $_.IPAddress -SubnetMask $_.SubnetMask -DefaultGateway $_.DefaultGateway -DNS $_.DNS

New-VM -Name $_.Name -Template "Microsoft Windows 2003 R2 Standard x86" -VMHost $_.VMHost -Location $_.Location -Datastore $_.Datastore -diskstorageformat Thin -OSCustomizationSpec "Microsoft Windows 2003 R2 Standard x86"

Regards,

Dimitar

0 Kudos
GrantOrchardVMw
Commander
Commander
Jump to solution

Thanks Dimitar... now that you've said that it makes perfect sense.

Grant

Grant http://grantorchard.com
0 Kudos