Showing posts with label MDTDB powershell module. Show all posts
Showing posts with label MDTDB powershell module. Show all posts

Saturday, August 24, 2013

MDX technical design

Hi folks, as promised i present the next part of my MDX posts. This time i will elaborate on the technical part of MDX as well as give you, the reader, a view of how  OS deployments are done; the MDX way.

MDX design; technical facts

MDX is build in PowerShell, the GUI is designed in SAPIEN’s Primal Forms Community Edition and the application is programmed in Microsoft’s own PowerShell ISA. the script counts around 3000 lines of code of which roughly 2000 lines are accounted for by the GUI. the script is divided in 15 Functions and 6 sections.

The general idea of the applications is: unification and simplification of MDT and accompanying tools to an end-to-end deployment solution.

mdx opbouw

Architecture

MDX is designed around the functionality of a few components:

Here is the graphical representation of the design

Architecture MDX

MDX has a few sections that do the work. each section does a part of the total solution; for example there is a section in MDX that accepts input from the GUI checks its validity and, if verified, adds or modifies a corresponding computer item in MDT- in its database. another section does communicate with PzExec.exe and adds the needed variables to the tools to get a deployment started.

How does MDT accomplish end-to-end automated deployment?

The ‘secret’ of MDX is the way all under laying components are ‘orchestrated’ to make a ‘deployment symphony’ …. the way MDX does this is as follows:

  • MDX controls the MDT database (which is crucial for end-to-end automated deployments) via PowerShell
  • MDX takes variables from the UI and combines it with preconfigured components in MDT and other used tools
  • MDX manipulates a computer object from the MDT database in such a way that it is deployment ready
  • MDX adds ‘non standard’ items or features to the preconfigured building blocks like: for example: add a few applications to the deployment of a certain computer and adds a user account as local administrator to the same deployment as well
  • MDX controls the WDS PXE server and thus controls who may- and may not boot to PXE and do a deployment via the network
  • MDX can directly fire a preconfigured computer to do a deployment.

What is to be expected from doing deployments with MDX

Apart from the fact that MDX takes away the direct interaction with MDT, MDX will give the User direct control over all building blocks of the deployment chain from a single GUI. the user can start off with a computer name, check the settings and modify them and fire of the deployment to the machine.

One important thing to realize is: MDX will help the user to select ALL settings and set them without the possibility of human error (like typing). MDX eases these tasks by presenting a simple but effective UI that will help de user select those things needed MUCH faster AND easier than when he- or she would do manually in MDT itself. as a bonus it eases the management of tools like WDS or the start of MDT deployment in the traditional way.

The next post will present a real world example of deployment with MDX. till next time.

Friday, March 22, 2013

Doing Custom Drive Configuration MDT without changing Task Sequence using PowerShell

This post elaborates on the MDTDB PowerShell module from Michael Niehaus link URL and configures the drives using PowerShell. it does this without altering the Task Sequence.

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 


Wednesday, March 20, 2013

Getting started with Michael Niehaus’s MDT module

Michael Niehaus published his MDT PowerShell Database module on May 15, 2009.
URL: http://blogs.technet.com/b/mniehaus/archive/2009/05/15/manipulating-the-microsoft-deployment-toolkit-database-using-powershell.aspx
this plugin is an extension to the standard MDT plugins and modules. it is targeted to the MDT database opposite most other MDT plugin’s that are mainly created to help you to modify the deployment share and its contents.
Unfortunately Michaels own blog is not very helpful in the application of the module so in this post i would like to help you to get started.


Organization of the Functions

The plugins are grouped into 5 units: new- ,set- ,get- ,clear- and remove -MDT*
All create-able and settable MDT items are handled generally in the same way:
  1. retrieve the Object ID
  2. set the Object with the option: –settings
the –settings property's are set individually like –settings (OSInstall=”Yes”) or with a hash table like –settings @(objectitem1=”text”;objectitem2=”text”;objectitem3=”text”}
The settings that can be used in the hash table are published on my blog on URL: http://negyuhsit.blogspot.nl/2013/03/mdt-computer-object-property-details.html
Each function group has the same kind of commands. let’s look at them right now.


New-MDT functions

The New-MDT*  group is the first group of all functions in this module. these functions are for the single purpose of the creation of MDT Objects
CommandType Name
----------- ----
Function New-MDTComputer
Function New-MDTLocation
Function New-MDTMakeModel
Function New-MDTPackageMapping
Function New-MDTRole
Syntax of New-MDTComputer: New-MDTComputer identifier –description OSDComputerName –settings @(objectitem1=”text”;objectitem2=”text”;objectitem3=”text”}

the identifier variable deserves some extra clarification: as identifier of a MDT object the following items can be used; at least one of them has to be defined:

-assetTag           uses the assetTag as identifier                     example:  E123456
-macAddress     uses the MAC address as identifier             example:  00:12:34:56:78
-serialNumber  uses the serialnumber of the machine          example:  12345678
-UUID              uses the UUID as identifier                          example: 329800735698586629295641978511506172918 (more information about UUID’s can be found on this link)

Syntax of New-MDTLocation:  New-MDTLocation –name LocationName –gateways IPADDRESSGW1,IPADDRESSGW2 –settings @(objectitem1=”text”;objectitem2=”text”;objectitem3=”text”}

Syntax of New-MDTMakeModel: New-MDTMakeModel –make Makename (example: HP, Dell) –model ModelName settings @(objectitem1=”text”;objectitem2=”text”;objectitem3=”text”}

Syntax of New-MDTPackageMapping: New-MDTPackageMapping –ARPName –package used to create mapping to packages on external systems like SCCM

Syntax of New-MDTRole: New-MDTRole –name RoleName settings @(objectitem1=”text”;objectitem2=”text”;objectitem3=”text”}


Set-MDT* and Get-MDT*

Of the next two groups Set-MDT* and Get-MDT* ,the first function is the one that realy does configure MDT Objects. they do this in the following way:
Get-MDT* –ID mdtitemID –settings @(objectitem1=”text”;objectitem2=”text”;objectitem3=”text”}
The second function (Get-MDT*) is mainly there to fetch MDT object and to extract their ID's to use them in a Set command.
The way to retrieve the object ID is done like this: (Get-MDTComputer -macAddress $mac).ID where the MAC address is in a format like nn:nn:nn:nn:nn but offcourse the other three object identifiers can also be used to retrieve the object ID.
Another way to retrieve the ID of an object is to open the MDT MMC and look for the object, the ID is found in the table and in the GUI Tabs:

image

CommandType Name
----------- ----
Function Set-MDTArray
Function Set-MDTComputer
Function Set-MDTComputerAdministrator
Function Set-MDTComputerApplication
Function Set-MDTComputerPackage
Function Set-MDTComputerRole
Function Set-MDTLocation
Function Set-MDTLocationAdministrator
Function Set-MDTLocationApplication
Function Set-MDTLocationPackage
Function Set-MDTLocationRole
Function Set-MDTMakeModel
Function Set-MDTMakeModelAdministrator
Function Set-MDTMakeModelApplication
Function Set-MDTMakeModelPackage
Function Set-MDTMakeModelRole
Function Set-MDTPackageMapping
Function Set-MDTRole
Function Set-MDTRoleAdministrator
Function Set-MDTRoleApplication
Function Set-MDTRolePackage
Function Set-MDTRoleRole

CommandType Name
----------- ----
Function Get-MDTArray
Function Get-MDTComputer
Function Get-MDTComputerAdministrator
Function Get-MDTComputerApplication
Function Get-MDTComputerPackage
Function Get-MDTComputerRole
Function Get-MDTLocation
Function Get-MDTLocationAdministrator
Function Get-MDTLocationApplication
Function Get-MDTLocationPackage
Function Get-MDTLocationRole
Function Get-MDTMakeModel
Function Get-MDTMakeModelAdministrator
Function Get-MDTMakeModelApplication
Function Get-MDTMakeModelPackage
Function Get-MDTMakeModelRole
Function Get-MDTRole
Function Get-MDTRoleAdministrator
Function Get-MDTRoleApplication
Function Get-MDTRolePackage
Function Get-MDTRoleRole

The Clear-MDT* group

This group functions generally the same like the  Get-MDT* group. just like that function, MDT objects are cleared like this: Clear-MDT* –ID MDTObjectID
CommandType Name
----------- ----
Function Clear-MDTArray
Function Clear-MDTComputerAdministrator
Function Clear-MDTComputerApplication
Function Clear-MDTComputerPackage
Function Clear-MDTComputerRole
Function Clear-MDTLocationAdministrator
Function Clear-MDTLocationApplication
Function Clear-MDTLocationPackage
Function Clear-MDTLocationRole
Function Clear-MDTMakeModelAdministrator
Function Clear-MDTMakeModelApplication
Function Clear-MDTMakeModelPackage
Function Clear-MDTMakeModelRole
Function Clear-MDTRoleAdministrator
Function Clear-MDTRoleApplication
Function Clear-MDTRolePackage
Function Clear-MDTRoleRole

Remove-MDT* group

This group is the opposite of the New_MDT* group: it removes MDT objects from the MDT database.
They function generally the same like the Set- and Get-MDT* groups. just like those functions the MDT object are removed like this: Remove-MDT* –ID MDTObjectID
CommandType Name
----------- ----
Function Remove-MDTComputer
Function Remove-MDTLocation
Function Remove-MDTMakeModel
Function Remove-MDTPackageMapping
Function Remove-MDTRole

All groups have some main functions like –verbose these are used for level of feedback to the user.

Tags van Technorati: ,,,,