VMware Cloud Community
BenLiebowitz
Expert
Expert
Jump to solution

Trying to create Customization Specifications for a new Environment with PowerCLI

So, we just deployed a new vCenter and I need to create new customizations.  I decided to script it as we typically have 3-4 customizations for each vLAN to set the default gateway / mask.  The customization gets created, but I'm getting an error with the New-OSCustomizationNICMapping command.

The CSV contains:

vLAN_ID     IP_Range            Mask                   Gateway

10                10.10.10.0/24       255.255.255.0     10.10.10.1

Error:

New-OSCustomizationNicMapping : A positional parameter cannot be found that

accepts argument '10.10.10.1'.

At E:\ps1\vmware\Customizations.ps1:40 char:2

+     New-OSCUstomizationNICMapping -OSCustomizationSpec "$($Win2016)_v ...

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

    + CategoryInfo          : InvalidArgument: (:) [New-OSCustomizationNicMapp

   ing], ParameterBindingException

    + FullyQualifiedErrorId : PositionalParameterNotFound,VMware.VimAutomation

   .ViCore.Cmdlets.Commands.NewOSCustomizationNicMapping

Here's my script:

###########################################################

#

# PowerCLI Script to create Customization Specifications

# Created by BLiebowitz on 9/18/2017

#

###########################################################

# Set Local Administrator Credentials

write-host "."

write-host "Enter the local admin password."

write-host "."

$CRED_Local = get-credential -credential Administrator

write-host "."

write-host "Enter the svc_storage password."

write-host "."

$CRED_Domain = get-credential -credential Domain\user1

# Set Org Variables

$OrgName = "Company"

$OrgUser = "Company User"

# Set Customization Name Variables

$Win2016 = "Win2016 Std - Sysprep Settings"

$Win2012 = "Win2012R2 Std - Sysprep Settings"

$Win2008R2S = "Win2008R2 - Std Sysprep Settings"

$Win2008R2E = "Win2008R2 - Ent Sysprep Settings"

# Set variables for KMS keys

$2016Key = "WC2BQ-8NRM3-FDDYY-2BFGV-KHKQY"

$2012Key = "D2N9P-3P6X9-2R39C-7RTCD-MDVJX"

$2008SKey = "YC6KT-GKW9T-YTKYR-T4X34-R7VHC"

$2008EKey = "489J6-VHDMP-X63PK-3K798-CPX3Y"

foreach ($row in (Import-csv -path e:\ben\vmware\portgroups.csv)) {

# Get the vLAN ID from CSV

$vlan = $row.vLAN_ID

$Gateway = $row.Gateway

$Mask = $row.Mask

$Description = $row.IP_Range

# Create the specifications and NIC Mappings for Win2016

New-OSCustomizationSpec -Name "$($Win2016)_vLAN-$($vlan)_($Description)" -OSType Windows -Type Persistent -TimeZone 035 -ProductKey $2016Key -FullName $OrgUser -OrgName $OrgName -AdminPassword $cred_Local -DomainCredentials $CRED_Domain -Domain "Domain.com" -NamingScheme VM -AutoLogonCount 1 -DNSServer "10.10.10.10", "10.10.10.11" -ChangeSID:$true -Confirm:$false

New-OSCUstomizationNICMapping -OSCustomizationSpec "$($Win2016)_vLAN-$($vlan)_($Description)" -ipmode PromptUser -DefaultGateway $Gateway –SubnetMask $Mask

}

Ben Liebowitz, VCP vExpert 2015, 2016, & 2017 If you found my post helpful, please mark it as helpful or answered to award points.
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Ok, then update the settings on the default 1st NIC.

###########################################################

#

# PowerCLI Script to create Customization Specifications

# Created by BLiebowitz on 9/18/2017

#

###########################################################

# Set Local Administrator Credentials

write-host "."

write-host "Enter the local admin password."

write-host "."

$CRED_Local = Get-Credential -credential Administrator

write-host "."

write-host "Enter the svc_storage password."

write-host "."

$CRED_Domain = Get-Credential -credential Domain\user1

# Set Org Variables

$OrgName = "Company"

$OrgUser = "Company User"

# Set Customization Name Variables

$Win2016 = "Win2016 Std - Sysprep Settings"

$Win2012 = "Win2012R2 Std - Sysprep Settings"

$Win2008R2S = "Win2008R2 - Std Sysprep Settings"

$Win2008R2E = "Win2008R2 - Ent Sysprep Settings"

# Set variables for KMS keys

$2016Key = "WC2BQ-8NRM3-FDDYY-2BFGV-KHKQY"

$2012Key = "D2N9P-3P6X9-2R39C-7RTCD-MDVJX"

$2008SKey = "YC6KT-GKW9T-YTKYR-T4X34-R7VHC"

$2008EKey = "489J6-VHDMP-X63PK-3K798-CPX3Y"

foreach ($row in (Import-csv -path e:\ben\vmware\portgroups.csv)) {

# Get the vLAN ID from CSV

    $vlan = $row.vLAN_ID

    $Gateway = $row.Gateway

    $Mask = $row.Mask

    $Description = $row.IP_Range

# Create the specifications and NIC Mappings for Win2016

    Get-OSCustomizationSpec -Name "$($Win2016)_vLAN-$($vlan)_($Description)" -ErrorAction SilentlyContinue |

    Remove-OSCustomizationSpec -Confirm:$false

    $sCust = @{

         Name = "$($Win2016)_vLAN-$($vlan)_($Description)"

         OSType = 'Windows'

         Type = 'Persistent'

         TimeZone = 035

         ProductKey = $2016Key

         FullName = $OrgUser

         OrgName = $OrgName

         AdminPassword = $cred_Local

         DomainCredentials = $CRED_Domain

         Domain = "Domain.com"

         NamingScheme = 'VM'

         AutoLogonCount = 1

         ChangeSID = $true

         Confirm = $false

    }

    $cust = New-OSCustomizationSpec @sCust

    $sCustNic = @{

        ipmode = 'PromptUser'

        DefaultGateway = $Gateway

        SubnetMask = $Mask

        Dns = "10.10.10.10","10.10.10.11"

    }

    Get-OSCustomizationNicMapping -OSCustomizationSpec $cust |

    Set-OSCustomizationNicMapping @sCustNic

}


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

View solution in original post

Reply
0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

Try like this.

Don't pass the name of the OSCustomizationSpec, but use the object itself (returned by the New-OSCustomizationSpec cmdlet).

Note that DnsServer is only valid when the OSType is Linux.

And see how splatting makes this a lot more readable :smileygrin:

###########################################################

#

# PowerCLI Script to create Customization Specifications

# Created by BLiebowitz on 9/18/2017

#

###########################################################

# Set Local Administrator Credentials

write-host "."

write-host "Enter the local admin password."

write-host "."

$CRED_Local = Get-Credential -credential Administrator

write-host "."

write-host "Enter the svc_storage password."

write-host "."

$CRED_Domain = Get-Credential -credential Domain\user1

# Set Org Variables

$OrgName = "Company"

$OrgUser = "Company User"

# Set Customization Name Variables

$Win2016 = "Win2016 Std - Sysprep Settings"

$Win2012 = "Win2012R2 Std - Sysprep Settings"

$Win2008R2S = "Win2008R2 - Std Sysprep Settings"

$Win2008R2E = "Win2008R2 - Ent Sysprep Settings"

# Set variables for KMS keys

$2016Key = "WC2BQ-8NRM3-FDDYY-2BFGV-KHKQY"

$2012Key = "D2N9P-3P6X9-2R39C-7RTCD-MDVJX"

$2008SKey = "YC6KT-GKW9T-YTKYR-T4X34-R7VHC"

$2008EKey = "489J6-VHDMP-X63PK-3K798-CPX3Y"

foreach ($row in (Import-csv -path e:\ben\vmware\portgroups.csv)) {

# Get the vLAN ID from CSV

    $vlan = $row.vLAN_ID

    $Gateway = $row.Gateway

    $Mask = $row.Mask

    $Description = $row.IP_Range

# Create the specifications and NIC Mappings for Win2016

    Get-OSCustomizationSpec -Name "$($Win2016)_vLAN-$($vlan)_($Description)" -ErrorAction SilentlyContinue |

    Remove-OSCustomizationSpec -Confirm:$false

    $sCust = @{

         Name = "$($Win2016)_vLAN-$($vlan)_($Description)"

         OSType = 'Windows'

         Type = 'Persistent'

         TimeZone = 035

         ProductKey = $2016Key

         FullName = $OrgUser

         OrgName = $OrgName

         AdminPassword = $cred_Local

         DomainCredentials = $CRED_Domain

         Domain = "Domain.com"

         NamingScheme = 'VM'

         AutoLogonCount = 1

         ChangeSID = $true

         Confirm = $false

    }

    $cust = New-OSCustomizationSpec @sCust

    $sCustNic = @{

        OSCustomizationSpec = $cust

        ipmode = 'PromptUser'

        DefaultGateway = $Gateway

        SubnetMask = $Mask

        Dns = "10.10.10.10","10.10.10.11"

    }

    New-OSCUstomizationNICMapping @sCustNic

}


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

BenLiebowitz
Expert
Expert
Jump to solution

Luc,

This worked, however the NIC Mapping created a 2nd NIC.  The 1st in the customization is set to UseDHCP.  If I add the Position parameter, it just moves the PromptUser NIC to NIC1 and UseDHCP to NIC2. 

I only need 1 NIC. 

Ben Liebowitz, VCP vExpert 2015, 2016, & 2017 If you found my post helpful, please mark it as helpful or answered to award points.
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Ok, then update the settings on the default 1st NIC.

###########################################################

#

# PowerCLI Script to create Customization Specifications

# Created by BLiebowitz on 9/18/2017

#

###########################################################

# Set Local Administrator Credentials

write-host "."

write-host "Enter the local admin password."

write-host "."

$CRED_Local = Get-Credential -credential Administrator

write-host "."

write-host "Enter the svc_storage password."

write-host "."

$CRED_Domain = Get-Credential -credential Domain\user1

# Set Org Variables

$OrgName = "Company"

$OrgUser = "Company User"

# Set Customization Name Variables

$Win2016 = "Win2016 Std - Sysprep Settings"

$Win2012 = "Win2012R2 Std - Sysprep Settings"

$Win2008R2S = "Win2008R2 - Std Sysprep Settings"

$Win2008R2E = "Win2008R2 - Ent Sysprep Settings"

# Set variables for KMS keys

$2016Key = "WC2BQ-8NRM3-FDDYY-2BFGV-KHKQY"

$2012Key = "D2N9P-3P6X9-2R39C-7RTCD-MDVJX"

$2008SKey = "YC6KT-GKW9T-YTKYR-T4X34-R7VHC"

$2008EKey = "489J6-VHDMP-X63PK-3K798-CPX3Y"

foreach ($row in (Import-csv -path e:\ben\vmware\portgroups.csv)) {

# Get the vLAN ID from CSV

    $vlan = $row.vLAN_ID

    $Gateway = $row.Gateway

    $Mask = $row.Mask

    $Description = $row.IP_Range

# Create the specifications and NIC Mappings for Win2016

    Get-OSCustomizationSpec -Name "$($Win2016)_vLAN-$($vlan)_($Description)" -ErrorAction SilentlyContinue |

    Remove-OSCustomizationSpec -Confirm:$false

    $sCust = @{

         Name = "$($Win2016)_vLAN-$($vlan)_($Description)"

         OSType = 'Windows'

         Type = 'Persistent'

         TimeZone = 035

         ProductKey = $2016Key

         FullName = $OrgUser

         OrgName = $OrgName

         AdminPassword = $cred_Local

         DomainCredentials = $CRED_Domain

         Domain = "Domain.com"

         NamingScheme = 'VM'

         AutoLogonCount = 1

         ChangeSID = $true

         Confirm = $false

    }

    $cust = New-OSCustomizationSpec @sCust

    $sCustNic = @{

        ipmode = 'PromptUser'

        DefaultGateway = $Gateway

        SubnetMask = $Mask

        Dns = "10.10.10.10","10.10.10.11"

    }

    Get-OSCustomizationNicMapping -OSCustomizationSpec $cust |

    Set-OSCustomizationNicMapping @sCustNic

}


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

Reply
0 Kudos
BenLiebowitz
Expert
Expert
Jump to solution

Luc,

This worked!  Thanks! 

Luc to the rescue!  Next time I need help, I'm sending up the LUC SIGNAL! 

Luc_Signal.jpg

Ben Liebowitz, VCP vExpert 2015, 2016, & 2017 If you found my post helpful, please mark it as helpful or answered to award points.
Reply
0 Kudos
m3llow
Contributor
Contributor
Jump to solution

Hi Ben,

This looks like it will be useful to me; thanks for sharing your work. 

Not sure if you wanted to expose your KMS keys ...?

Mel

BenLiebowitz
Expert
Expert
Jump to solution

They're not my keys.  They're KMS keys to allow windows to activate via KMS.  You can find them here:

Appendix A: KMS Client Setup Keys

Ben Liebowitz, VCP vExpert 2015, 2016, & 2017 If you found my post helpful, please mark it as helpful or answered to award points.
Reply
0 Kudos