Prestaging a VMWare VM in Windows Active Directory
# Modules needed for this function to work, remember you need to be connected to vCenter aswell! | |
# Load VMware Module | |
if ((Get-PSSnapin | Where-Object { $_.Name -eq "VMware.VimAutomation.Core" }) -eq $null) { Add-PSSnapin VMware.VimAutomation.Core } | |
# Load AD Module... if you can't import it you need Windows RSAT http://www.microsoft.com/en-us/download/details.aspx?id=7887 | |
if ((Get-Module | Where-Object { $_.Name -eq "ActiveDirectory" }) -eq $null) { Import-Module ActiveDirectory } | |
# Variables Needed | |
[String]$vmName = (Read-Host "Provide VM Name") | |
$domainName = "just.fen.co.uk" | |
# Function to grab the VMs UUID and prestage this in AD, will allow all GPO's and Sec Groups to apply as it joins domain | |
function PrestageVM { | |
# This line will grab the GUID needed to prestage the machine | |
[guid]$vmGUID = Get-VM $vmName | % {(Get-View $_.id).config.uuid} | |
New-PSDrive -PSProvider ActiveDirectory -Name ADDrive -Root "" -Server "$domainName" | |
pushd ADDrive: | |
# As you make the VM in AD, you can add additional things such as description, here we use the flavour and size of template used for example | |
New-ADComputer -Name "$vmName" -samAccountName "$vmName" -Description "$vmsize $vmFlavour Server" -OtherAttributes @{'netbootGUID'=$vmGUID} | |
popd | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment