Jump to content
  • 0

Script Powershell to create VM


kevin blais

Question

Hi Readers,

 

I'm trying to automate the creation of VM by a powershell script with citrix studio and i have 1 little issues but i don't know how to pass that ...

 

Here's a part of my script <<

 

$Pool = Get-BrokerCatalog -Name $CAName -AdminAddress $AdminAddress


New-AcctADAccount -IdentityPoolName $CAName -Count 1 -AdminAddress $AdminAddress 


$ADAccount = Get-AcctAdAccount -IdentityPoolName $CAName -State Available


New-ProvVM -ProvisioningSchemeName $Pool.Name -ADAccountname $ADAccount.ADAccountName -Adminaddress $AdminAddress

 

>> 

So Citrix take the next name avalaible according to template's done but "New-ProvVm" create the name but there's no way to go search the information  like the Name of the VM Created (That i need)

 

if you could help me would be great thanks :)

Link to comment

3 answers to this question

Recommended Posts

  • 0

I've not tested it myself, but one of my peers created this script.  It will output a CSV of the VMs that were created.

 

import-module ActiveDirectory
$NamingConvention = "TEST-VDI" # this is the prefix to the ComputerName matching internal naming convention
$buildcount = 9
$list = @()
$date = (get-date).ToShortDateString().Replace("/",".")
$path = "\\redacted.net\tsresource\data\temp\" + $NamingConvention + "." + $date + ".csv" # Path to Logfile 

for ($i = 1; $i -le $buildcount){
    $rand = get-random -Maximum 9999999
    If ($rand.tostring().length -lt 7){
        do {
            $rand = $rand * 10
            }
        While ($rand.tostring().length -lt 7)
    }
    $computername = $NamingConvention + $rand
    try {
        get-adcomputer $computername # Check if our generated ComputerName already exists
        }

    catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException] {
        If (Test-NetConnection $computername -InformationLevel Quiet){
            write-host "$computername responded!" # Name exists, will need to try again
        }
        Else {
        new-adcomputer -name $computername -SAMAccountName $computername -path "OU=XenDesktop,OU=DEVELOPMENT,DC=REDACTED,DC=NET"
        $out = New-Object psobject -property @{
            "[ADComputerAccount]" = $computername # ComputerName did not exist, let's create it.
        }
        $list += $out
        $i++
        }
    }
}
$list | Export-Csv -NoTypeInformation $path

 

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...