Quantcast
Channel: Deployment Research - Johan Arwidmark
Viewing all articles
Browse latest Browse all 168

PowerShell wrapper for MDT 2012 Update 1 and MDT 2013 Preview

$
0
0

For the last ten years or so, VB Script wrappers have been popular due to the fact they have been available by default in the platforms. Now, in a time where most companies deploy either Windows 7 or Windows 8, there are other options, like PowerShell (PowerShell is King!).

MDT 2012 Update 1 and MDT 2013 Preview does have the option of calling PowerShell scripts natively from the task sequence, but I normally don’t do that for the following reasons.

  1. I like to have my scripts as applications because they are easy to import/export
  2. The MDT PowerShell is picky about what you do in your scripts, as well as a being sensitive to PowerShell Group Policies.

The perfect solution – Create your own wrapper and call it via PowerShell.exe

Example: Here is a PowerShell script I use to create sites and subnets in Active Directory

<#
Solution: Hydration
Purpose: Used to create AD Sites and Subnets
Version: 1.2 - January 10, 2013

This script is provided "AS IS" with no warranties, confers no rights and 
is not supported by the authors or Deployment Artist. 

Author - Johan Arwidmark
    Twitter: @jarwidmark
    Blog   : http://deploymentresearch.com
#>


# Determine where to do the logging 
$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment 
$logPath = $tsenv.Value("LogPath") 
$logFile = "$logPath\$($myInvocation.MyCommand).log" 

# Start the logging 
Start-Transcript $logFile 
Write-Host "Logging to $logFile" 

# Start Main Code Here

# Create Empty AD Sites (sites with no domain controllers, for lab purpose only)
New-ADReplicationSite -Name Stockholm
New-ADReplicationSite -Name Liverpool

# Create AD Subnets 
New-ADReplicationSubnet -Name "192.168.1.0/24" -Site NewYork
New-ADReplicationSubnet -Name "192.168.2.0/24" -Site Stockholm
New-ADReplicationSubnet -Name "192.168.3.0/24" -Site Liverpool

# Stop logging 
Stop-Transcript
To run this script via the task sequence, I simply create an application with the following command line
powershell.exe -Command "set-ExecutionPolicy Unrestricted -Force; cpi '%DEPLOYROOT%\Applications\Configure - Create AD Subnets\Configure-CreateADSubnets.ps1' -destination c:\; c:\Configure-CreateADSubnets.ps1; ri c:\*.ps1 -Force; set-ExecutionPolicy Restricted -Force"

 

/ Johan


More ...

Viewing all articles
Browse latest Browse all 168

Trending Articles