Just to circle back, for anyone who may search for similar in the future, this is as far as I have come thus far:
The build script reads in the csv, producing an array of machines to be built, like so:
Name | CPU | RAM | IP | NetMask | Gateway | DNS1 | DNS2 | PortGroup | Folder | Description | Compute_Cluster | DataStore_Cluster | Template | Location | Domain | SQL | Drive1Size | Drive2Letter | Drive2Size | Drive2Name | Drive3Letter | Drive3Size | Drive3Name | Drive4Letter | Drive4Size | Drive4Name | Drive5Letter | Drive5Size | Drive5Name | OSType | OSArch | Owner | Environment | Request | |
---|
JLoTest01 | 2 | 4 | 172.24.16.25 | 255.255.248.0 | 172.24.16.6 | 172.24.16.2 | 172.24.16.3 | dvportGroup_VLAN22 | Testing | Testing | CXO_Production | CMO_I_Non-Prod | 2016_DE | OK | INTRA | No | 100 | F | 30 | Logs | G | 150 | Apps | I | 90 | Backup | J | 120 | Rollover | Windows | 2016 | Hosting | Sandbox | 123456 | |
The foreach loop takes each VM object and runs it through the various build processes. At the end, on the newly built server, if I pull in that same VM object from the csv, I can use this function to prepare the disks:
Function _initializeDisks {
[CmdLetBinding()]
Param (
[Parameter(Mandatory, Position=1)]
$oServer
)
$aFinal = @()
$aRawDisks = gwmi win32_diskdrive |
where {$_.Partitions -eq 0} |
Select @{n="Number";e={$_.index}}, @{n="Size"; e={[math]::Round(((($_.Size / 1024) /1024) / 1024))}} |
Sort Number
foreach($a in 2..5) {
$sLetter = "Drive$($a)Letter"
$sSize = "Drive$($a)Size"
$sName = "Drive$($a)Name"
if(!([string]::IsNullOrEmpty($oServer.$sSize))) {
foreach ($disk in $aRawDisks) {
if ($oServer.$sSize -eq $disk.Size) {
$aFinal += New-Object PSObject -Property @{DriveLetter=$($oServer.$sLetter);Number=$($disk.Number);Size=$($disk.Size);Description=$($oServer.$sName)}
}
}
}
}
foreach($newDrive in $aFinal) {
Initialize-Disk -Number $newDrive.Number -PartitionStyle GPT
$sDrive = New-Partition -DiskNumber $newDrive.Number -AssignDriveLetter -UseMaximumSize
Format-Volume -DriveLetter $sDrive.DriveLetter -FileSystem NTFS
Set-Volume -DriveLetter $sDrive.DriveLetter -NewFileSystemLabel $newDrive.Description
Set-Partition -DriveLetter $sDrive.DriveLetter -NewDriveLetter $newDrive.DriveLetter
Start-Sleep 1
$sCommand = "select disk $($newDrive.Number)`r`nconvert dynamic"
$sCommand | diskpart
}
}
This works great, but again has to be after someone logs into the new server and manually runs it. I have yet to be able to use Invoke-VMScript to do this process; cannot seem to pass the VM object through. Hope to overcome that hurdle at some point and make this fully automated.