VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Issue creating multiple customization from csv file

Hi,

I am trying to create multiple customizations using input csv file. Whilte creating a customisation, I am unable to get the variable value populated to customization template. Please help.

csv contents

Folder,Group1,Group2,OU
Testing,mygroup1,mygroup2,OU=Servers,OU=POC,DC=mycopr,DC=com
Testing34,mygroup2,mygroup3,OU=Servers1,OU=POC,DC=mycopr,DC=com

 
Script    
$vm = (get-vm SQL01).Folder.Name
Import-Csv -Path ".\poc_groups.csv" -UseCulture -PipelineVariable row | where {($vm -eq $row.folder)} |
ForEach-Object -Process {
$sCust = @{
         Name = "MyTeam-$($date)"
         OSType = 'Windows'
         TimeZone = 020
         ProductKey = 'XXXXX-XXXXX-XXXXX-XXXXX-XXXXX'
LicenseMode = 'Perserver'
LicenseMaxConnections = 5
GuiRunOnce = '"C:\Windows\System32\netdom.exe" join %COMPUTERNAME% /domain:mycopr.com /ou:$row.OU /userd:mycopr.com\admin1 /passwordd:"Password123" /reboot', 'net localgroup Administrators /ADD groupname $row.Group1'
Type = 'Persistent'
         NamingScheme = 'VM'
         Workgroup = 'WORKGROUP'
         }
    $Custo = New-OSCustomizationSpec @sCust
    $sCustNic = @{
IpMode = 'UseDhcp'
    }
Get-OSCustomizationSpec $Custo
}

 

 

 

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Ad the quotes in the code. They need to be double since you already are inside double quotes.

         GuiRunOnce            = """C:\Windows\System32\netdom.exe"" join %COMPUTERNAME% /domain:mycopr.com /ou:""$($row.OU)"" /userd:mycopr.com\admin1 /passwordd:""Password123"" /reboot",
                                 "net localgroup Administrators /ADD groupname $($row.Group1)"


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

View solution in original post

Reply
0 Kudos
10 Replies
LucD
Leadership
Leadership
Jump to solution

What do you mean by "I am unable to get the variable value populated to customization template"?
Are there any error messages?


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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

when I execute, I am getting the below error

ganapa2000_0-1691059819474.png

 

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

FullName is a required parameter when you create a CustomizationSpec for a Windows guest OS.
See New-OSCustomizationSpec, Windows parameterset.


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

ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

If I execute this code directly, it is working but if I use inside the import-csv loop it is not working

$sCust = @{
         Name = "MyTeam-$($date)"
         OSType = 'Windows'
         TimeZone = 020
         ProductKey = 'XXXXX-XXXXX-XXXXX-XXXXX-XXXXX'
LicenseMode = 'Perserver'
LicenseMaxConnections = 5
GuiRunOnce = '"C:\Windows\System32\netdom.exe" join %COMPUTERNAME% /domain:mycopr.com /ou:$row.OU /userd:mycopr.com\admin1 /passwordd:"Password123" /reboot', 'net localgroup Administrators /ADD groupname $row.Group1'
Type = 'Persistent'
         NamingScheme = 'VM'
         Workgroup = 'WORKGROUP'
         }
    $Custo = New-OSCustomizationSpec @sCust
    $sCustNic = @{
IpMode = 'UseDhcp'
    }
Get-OSCustomizationSpec $Custo

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

What is not working? Error message?
How did you implement the loop?


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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

We have multiple departments and I am trying to create a customization for every department. In the CSV file, we have Folder Name, AD Group Name and AD OU Name, while creating a VM in a particular department folder, a new customization needed to be created using csv file input for AD Group Name and AD OU. Now when I use the below script, it is not taking the complete OU details, it is just taking first part. Example my OU path is OU=Servers,OU=POC,DC=mycopr,DC=com, while creating a customization, it is just using OU=Servers

 

csv contents

Folder,Group1,Group2,OU
Testing,mygroup1,mygroup2,OU=Servers,OU=POC,DC=mycopr,DC=com
Testing34,mygroup2,mygroup3,OU=Servers1,OU=POC,DC=mycopr,DC=com

 
Script    
$vm = (get-vm SQL01).Folder.Name
Import-Csv -Path ".\poc_groups.csv" -UseCulture -PipelineVariable row | where {($vm -eq $row.folder)} |
ForEach-Object -Process {
$sCust = @{
         Name = "MyTeam-$($date)"
         OSType = 'Windows'
         TimeZone = 020
         ProductKey = 'XXXXX-XXXXX-XXXXX-XXXXX-XXXXX'
LicenseMode = 'Perserver'
LicenseMaxConnections = 5
GuiRunOnce = '"C:\Windows\System32\netdom.exe" join %COMPUTERNAME% /domain:mycopr.com /ou:$row.OU /userd:mycopr.com\admin1 /passwordd:"Password123" /reboot', 'net localgroup Administrators /ADD groupname $row.Group1'
Type = 'Persistent'
         NamingScheme = 'VM'
         Workgroup = 'WORKGROUP'
         }
    $Custo = New-OSCustomizationSpec @sCust
    $sCustNic = @{
IpMode = 'UseDhcp'
    }
Get-OSCustomizationSpec $Custo
}

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

There are a couple of problems.
You are using the same delimiter (comma) as used in the OU string.
With single quotes, there is no variable substitution.
To substitute with a property in an object ($row.OU and $row.Group1), enclose those in ${}

SO your CSV should ook something like this

Folder;Group1;Group2;OU
Testing;mygroup1;mygroup2;OU=Servers,OU=POC,DC=mycopr,DC=com
Testing34;mygroup2;mygroup3;OU=Servers1,OU=POC,DC=mycopr,DC=com

Then the code could be

$vm = (Get-VM SQL01).Folder.Name

Import-Csv -Path ".\poc_groups.csv" -UseCulture -Delimiter ';' -PipelineVariable row | where {($vm -eq $row.folder)} |
   ForEach-Object -Process {
      $sCust = @{
         Name                  = "MyTeam-$($date)"
         OSType                = 'Windows'
         TimeZone              = 020
         ProductKey            = 'XXXXX-XXXXX-XXXXX-XXXXX-XXXXX'
         LicenseMode           = 'Perserver'
         LicenseMaxConnections = 5
         GuiRunOnce            = """C:\Windows\System32\netdom.exe"" join %COMPUTERNAME% /domain:mycopr.com /ou:$($row.OU) /userd:mycopr.com\admin1 /passwordd:""Password123"" /reboot",
                                 "net localgroup Administrators /ADD groupname $($row.Group1)"
         Type                  = 'Persistent'
         NamingScheme          = 'VM'
         Workgroup             = 'WORKGROUP'
      }
      $Custo = New-OSCustomizationSpec @sCust
      $sCustNic = @{
         IpMode = 'UseDhcp'
      }
      Get-OSCustomizationSpec $Custo
   }

 


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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

Now I am able to create the customization but, how can I get double quotes included for complete OU details when calling from csv file.

Currently it just imports as 

OU=Servers,OU=POC,DC=mycopr,DC=com

but I need as

"OU=Servers,OU=POC,DC=mycopr,DC=com"
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Ad the quotes in the code. They need to be double since you already are inside double quotes.

         GuiRunOnce            = """C:\Windows\System32\netdom.exe"" join %COMPUTERNAME% /domain:mycopr.com /ou:""$($row.OU)"" /userd:mycopr.com\admin1 /passwordd:""Password123"" /reboot",
                                 "net localgroup Administrators /ADD groupname $($row.Group1)"


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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

That worked perfectly. Thank you Lucd. 🙂

Reply
0 Kudos