Automation

 View Only
  • 1.  Issue creating multiple customization from csv file

    Posted Aug 03, 2023 08:11 AM

    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
    }

     

     

     



  • 2.  RE: Issue creating multiple customization from csv file

    Posted Aug 03, 2023 08:53 AM

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



  • 3.  RE: Issue creating multiple customization from csv file

    Posted Aug 03, 2023 10:51 AM

    LucD,

    when I execute, I am getting the below error

    ganapa2000_0-1691059819474.png

     

     



  • 4.  RE: Issue creating multiple customization from csv file

    Posted Aug 03, 2023 11:31 AM

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



  • 5.  RE: Issue creating multiple customization from csv file

    Posted Aug 03, 2023 01:51 PM

    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

     



  • 6.  RE: Issue creating multiple customization from csv file

    Posted Aug 03, 2023 04:31 PM

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



  • 7.  RE: Issue creating multiple customization from csv file

    Posted Aug 09, 2023 04:56 AM

    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
    }

     



  • 8.  RE: Issue creating multiple customization from csv file

    Posted Aug 09, 2023 12:44 PM

    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
       }

     



  • 9.  RE: Issue creating multiple customization from csv file

    Posted Aug 09, 2023 04:06 PM

    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"


  • 10.  RE: Issue creating multiple customization from csv file
    Best Answer

    Posted Aug 09, 2023 04:51 PM

    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)"


  • 11.  RE: Issue creating multiple customization from csv file

    Posted Aug 10, 2023 07:31 AM

    That worked perfectly. Thank you Lucd.