The key to this is using a few MDT database variables:
- OSDPartitions0BOOTABLE=
- OSDPartitions0FILESYSTEM=
- OSDPartitions0QUICKFORMAT=
- OSDPartitions0SIZE=
- OSDPartitions0SIZEUNITS=
- OSDPartitions0TYPE=
- OSDPartitions0VOLUMELETTERVARIABLE=
- OSDPartitions0VOLUMENAME=
This variables will overrule de standard drive configuration defined in the Task Sequence. MDT can configure a maximum of 2 partitions (per disk) using the database variables OSDPartitions0 and OSDPartitions1Field OSDPartitions0SIZE will define the partition size in units specified in OSDPartitions0SIZEUNITS, these can be MB, GB or %. When using % this will define the percentage of remaining diskspace so if partition 0 was defined as 40Gb the specification of 100 % will result in the allocation of 100% of the rest of the remaining disk space to that second partition.
this script will use DHCP exports as created by another script you can find on my blog , if no, by DHCP exported MAC address, can be found the script will ask for a MAC address. it will check the MAC address for validity and the script will ask you to create a new MDTcomputer object if the machine cannot be found.
##################################
#
# this deployscript automates MDT using the database
# It configures the disk configuration of a new or existing computer object
# Functionality based on MDT plugin developed by Michael Niehaus
# Build by Bas Huygen
# March 2013
# Version 0.1
#################################
# Clear relevant variables
Clear-Host
Clear-Variable -Name computer
Clear-Variable -Name LASTEXITCODE
# import the relevant powershell modules and snapins
Import-Module D:\PSdeployripts\MDTDB\MDTDB.psm1 -Verbose
Add-PSSnapIn Microsoft.BDD.PSSnapIn
# Declare variables
$ErrorActionPreference= "SilentlyContinue"
$DeployServer = "deploy.deploy.lan"
$SQLServer = "deploySQL.deploy.lan"
$SQLInstance = "SQLExpress"
$MDTDatabaseName = "MDTdb"
$DHCPexport = "\\DHCP01\D$\PSdeployripts\Exports\exportDHCP.txt"
# Make a connection to the MDT database
Connect-MDTDatabase -SQLServer $SQLServer\$SQLInstance -Database $MDTDatabaseName
# Function Get-MAC $computer used to fetch MAC address
Function Get-MAC ($computer){
$macstr = 0
$maccnv = 0
if(!(Test-Path $DHCPexport)){Write-Host "path $DHCPexport is not valid"
$macstr =Get-Content Env:\TEMP\maccache.txt |where{$_ -like "*$computer*"}}
if($macstr.length -eq 0){
$maccnv= Read-Host ("$computer not found in cache `nEnter the MAC adress
`nFormat is xx:xx:xx:xx:xx:xx");
write "$computer $maccnv" |Out-File Env:\TEMP\maccache.txt -Append
# check the retreived MAC adress for validity
if($maccnv.Replace(":","").Length -ne 12) {
do{
Write-Host "Found $computer in DHCP however it is not valid: $maccnv"
$maccnv = Read-Host "Please enter a valid MAC address format is xx:xx:xx:xx:xx:xx";
}while ($maccnv.Replace(":","").Length -ne 12)
}
write "$computer $maccnv" |Out-File Env:\TEMP\maccache.txt -Append
}
else{ Write-Host "Found $computer with $maccnv"}
return $maccnv }
# Function set drive config entered by user
Function Drive-Config ($computer,$mac){
$config = Read-Host ("Please enter drive configuration: `n
-----------------------------------------------------------------
Standard disk configuration (1 partition all space allocated) (s) `
One custom partition rest not configured (1) `n
Two custom partitions (2)`n
-----------------------------------------------------------------
Please enter a choice (1,2,s)")
Switch ($config) {
1 {Set-MDTComputer -id $mac -settings @{OSDPartitions="1";
OSDPartitions0BOOTABLE="TRUE";
OSDPartitions0FILESYSTEM="NTFS";
OSDPartitions0QUICKFORMAT="TRUE";
OSDPartitions0SIZE=(Read-Host "The amount of GB's of the first drive");
OSDPartitions0SIZEUNITS="GB";
OSDPartitions0TYPE="Primary";
OSDPartitions0VOLUMELETTERVARIABLE="Newdrive1";
OSDPartitions0VOLUMENAME="OSDisk"
OSDPartitions1BOOTABLE="";
OSDPartitions1FILESYSTEM="";
OSDPartitions1QUICKFORMAT="";
OSDPartitions1SIZE="";
OSDPartitions1SIZEUNITS="";
OSDPartitions1TYPE="";
OSDPartitions1VOLUMELETTERVARIABLE="";
OSDPartitions1VOLUMENAME=""} > $null
}
2 {Set-MDTComputer -id $mac -settings @{OSDPartitions="2";
OSDPartitions0BOOTABLE="TRUE";
OSDPartitions0FILESYSTEM="NTFS";
OSDPartitions0QUICKFORMAT="TRUE";
OSDPartitions0SIZE=(Read-Host "The amount of GB's of the first drive");
OSDPartitions0SIZEUNITS="GB";
OSDPartitions0TYPE="Primary";
OSDPartitions0VOLUMELETTERVARIABLE="Newdrive1";
OSDPartitions0VOLUMENAME="OSDisk"
OSDPartitions1BOOTABLE="FALSE";
OSDPartitions1FILESYSTEM="NTFS";
OSDPartitions1QUICKFORMAT="TRUE";
OSDPartitions1SIZE=(Read-Host "The amount of GB's of the second drive");
OSDPartitions1SIZEUNITS="GB";
OSDPartitions1TYPE="Primary";
OSDPartitions1VOLUMELETTERVARIABLE="Newdrive2";
OSDPartitions1VOLUMENAME="Data" } > $null
}
s {Set-MDTComputer -id $mac -settings @{OSDPartitions="";
OSDPartitions0BOOTABLE="";
OSDPartitions0FILESYSTEM="";
OSDPartitions0QUICKFORMAT="";
OSDPartitions0SIZE="";
OSDPartitions0SIZEUNITS="";
OSDPartitions0TYPE="";
OSDPartitions0VOLUMELETTERVARIABLE="";
OSDPartitions0VOLUMENAME=""
OSDPartitions1BOOTABLE="";
OSDPartitions1FILESYSTEM="";
OSDPartitions1QUICKFORMAT="";
OSDPartitions1SIZE="";
OSDPartitions1SIZEUNITS="";
OSDPartitions1TYPE="";
OSDPartitions1VOLUMELETTERVARIABLE="";
OSDPartitions1VOLUMENAME=""} > $null
}
}
}
Clear-Host
$computer = Read-Host "Please enter Computer name"
write "Starting deployscript for $computer"
$mac = Get-MAC $computer
If(!((Get-MDTComputer -macAddress $mac).OSDComputerName -eq $computer)){
if($macstr -eq 0){Get-MAC $computer}
$newMDTComp = Read-Host "Make a new MDT Computer object? (y/n)"
if($newMDTComp -eq "y"){
New-MDTComputer -macAddress $mac -dedeployription $computer -settings @{OSInstall="YES";OSDComputerName="$computer"} > $null
Drive-Config $computer ((Get-MDTComputer -macAddress $mac).ID)}exit
}
else{Drive-Config $computer ((Get-MDTComputer -macAddress $mac).ID)}
happy OSD-ing