-
1. Re: Set some Vms parameters
LucD May 3, 2011 2:17 PM (in response to kopper27)1. You can set the network configuration in the OSCustomization spec with the New-OSCustomizationNicMapping and Set-OSCustomizationNicMapping cmdlets.
2. I'm afraid you can't use complex folder paths for the Location parameter.
But you can solve it like this
$folders = @($_.Location.Split('\'))
if($folders.Count -gt 1){
0..$folders.Count | %{
if($_ -eq 0){
$location = Get-Folder -Name $folders[$_]
}
else{
$location = Get-Folder -Name $folders[$_] -Location $location
}
}
else{
$location = Get-Folder -Name $folders[0]
}
In the New-VM cmdlet you can now do
New-VM ... -Location $location ...
-
2. Re: Set some Vms parameters
kopper27 May 12, 2011 1:24 PM (in response to LucD)thanks LucD
I am trying this to set IP....
$worksheet = Import-CSV "C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\NewVMs_v2.csv"
$worksheet | ForEach-Object {
new-VM `
-Name $_.VM_Name `
-VMHost $_.Host `
-Template $_.Template `
-Datastore $_.Datastore `
-OSCustomizationspec $_.Customization `
-Location $_.Location `
-DiskStorageFormat $_.DiskStorageFormat |`
Set-VM -NumCpu $_.CPU -MemoryMB $_.Memory -Confirm:$false
Start-VM -VM $_.VM_Name
New-HardDisk -VM $_.VM_Name -CapacityKB $_.New_HDD
Get-OSCustomizationSpec -OSCustomizationSpec $_.Customization | Set-OSCustomizationNicMapping -IpMode UseStaticIP `-IpAddress 10.6.26.12 -SubnetMask 255.255.255.0 -DefaultGateway 10.6.26.1 -Dns 10.6.25.53
}but I am getting this
Get-OSCustomizationSpec : A parameter cannot be found that matches parameter na
me 'OSCustomizationSpec'.
At C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\BatchVMs.ps1:14 char
:48
+ Get-OSCustomizationSpec -OSCustomizationSpec <<<< $_.Customization | S
et-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress 10.6.26.12 `
+ CategoryInfo : InvalidArgument: (:) [Get-OSCustomizationSpec],
ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,VMware.VimAutomation.ViCo
re.Cmdlets.Commands.GetOSCustomizationSpecany idea thanks a lot
-
3. Re: Set some Vms parameters
GrantOrchardVMware May 12, 2011 4:31 PM (in response to kopper27)Try this:
Get-OSCustomizationSpec -Name $_.Customization | Set-OSCustomizationNicMapping `
-IpMode UseStaticIP -IpAddress 10.6.26.12 -SubnetMask 255.255.255.0 `
-DefaultGateway 10.6.26.1 -Dns 10.6.25.53
EDIT: Also, you'll want to define your OSCustomizationSpec *before* you call "New-VM".
Grant
-
4. Re: Set some Vms parameters
kopper27 May 12, 2011 4:38 PM (in response to GrantOrchardVMware)Now I get this
I just saw your Edit update.I thunk thats the point I don't get define your OSCustomizationSpec *before* you call "New-VM".
I have to create a new one?
just to let you
Profile_Win2008_R2_x64 is the customization I use to create the templates in this case Windows 2008
Set-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 pipel
ine input.
At C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\BatchVMs.ps1:14 char
:82
+ Get-OSCustomizationSpec -Name $_.Customization | Set-OSCustomizationNic
Mapping <<<< -IpMode UseStaticIP -IpAddress 10.6.26.12 `
+ CategoryInfo : InvalidArgument: (Profile_Win2008_R2_x64:PSObjec
t) [Set-OSCustomizationNicMapping], ParameterBindingException
+ FullyQualifiedErrorId : InputObjectNotBound,VMware.VimAutomation.ViCore.
Cmdlets.Commands.SetOSCustomizationNicMapping
just to let you
Profile_Win2008_R2_x64 is the customization I use to create the templates in this case Windows 2008Set-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 pipel
ine input.
At C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\BatchVMs.ps1:14 char
:82
+ Get-OSCustomizationSpec -Name $_.Customization | Set-OSCustomizationNic
Mapping <<<< -IpMode UseStaticIP -IpAddress 10.6.26.12 `
+ CategoryInfo : InvalidArgument: (Profile_Win2008_R2_x64:PSObjec
t) [Set-OSCustomizationNicMapping], ParameterBindingException
+ FullyQualifiedErrorId : InputObjectNotBound,VMware.VimAutomation.ViCore.
Cmdlets.Commands.SetOSCustomizationNicMapping -
5. Re: Set some Vms parameters
GrantOrchardVMware May 12, 2011 5:09 PM (in response to kopper27)Apologies, that wasn't particularly clear. Here's what I was suggesting you do:
$worksheet = Import-CSV "C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\NewVMs_v2.csv"
$worksheet | ForEach-Object {
Get-OSCustomizationSpec -Name $_.Customization | Get-OSCustomizationNicMapping `
| Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress 10.6.26.12 `
-SubnetMask 255.255.255.0 -DefaultGateway 10.6.26.1 -Dns 10.6.25.53
new-VM `
-Name $_.VM_Name `
-VMHost $_.Host `
-Template $_.Template `
-Datastore $_.Datastore `
-OSCustomizationspec $_.Customization `
-Location $_.Location `
-DiskStorageFormat $_.DiskStorageFormat |`
Set-VM -NumCpu $_.CPU -MemoryMB $_.Memory -Confirm:$false
Start-VM -VM $_.VM_Name
New-HardDisk -VM $_.VM_Name -CapacityKB $_.New_HDD
}Let me know how you go.
Grant
-
6. Re: Set some Vms parameters
kopper27 May 16, 2011 10:45 AM (in response to GrantOrchardVMware)Now is working just fine
the first time I run it it complain about this
WARNING: 'Description' property is obsolete. Use 'Notes' instead.
WARNING: 'HardDisks' property is obsolete. Use 'Get-HardDisk' cmdlet instead.
WARNING: 'NetworkAdapters' property is obsolete. Use 'Get-NetworkAdapter' cmdlet instead.
WARNING: 'UsbDevices' property is obsolete. Use 'Get-UsbDevice' cmdlet instead.
WARNING: 'CDDrives' property is obsolete. Use 'Get-CDDrive' cmdlet instead.
WARNING: 'FloppyDrives' property is obsolete. Use 'Get-FloppyDrive' cmdlet instead.
WARNING: 'Host' property is obsolete. Use 'VMHost' instead.
WARNING: 'HostId' property is obsolete. Use 'VMHostId' instead.But now runs without problems
thanks a lot