Thursday, October 2, 2014

Backup and Restore a WIM from WinPE using DISM

Backup an image
  1. Boot from WinPE media.
  2. Determine the drive letter to be captured.  This is typically C:,D:, or E:, but it can vary depending on which devices are connected to the system.
  3. There are a few choices for where to back up the image, but my preference is to back it up to a network drive.  To do this, run the following command: 
    • Net use Z: \\<ServerName>\<DestinationPath>\
    • You should see “The command completed successfully” if it works correctly.  Remember, you need to have write permissions to this directory in order to save the image to it, so you should be prompted for credentials to connect to the share.
  4. DISM.exe should already be in the path environment variable in WinPE 5.0, so you can call the DISM executable from pretty much anywhere.
    • DISM.exe /Capture-Image /ImageFile:Z:\capture.wim /CaptureDir:E:\
    • Where Z: is the path to which you want to save the image and E: is the path to the partition with Windows installed.
    • If the drive contains much data, it will take an amount of time proportional the amount of data and the throughput of your network, USB, or eSATA connection.  Be patient
Restore an image
To restore an image to a new machine or a new drive, it is a very similar process, only the command in step 4 really changes.
  1. Boot from WinPE media.
  2. Determine the drive letter to restore the image.  This is typically C:,D:, or E:, but it can vary depending on which devices are connected to the system.
  3. If you used a network path to backup your image, you must re-map the drive again.  To do this, run the following command.
    • Net use Z: \\<ServerName>\<DestinationPath>\
    • You should see “The command completed successfully” if it works correctly.  Remember, you need to have write permissions to this directory in order to save the image to it, so you should be prompted for credentials to connect to the share.
  4. DISM.exe should already be in the path environment variable in WinPE 5.0, so you can call the DISM executable from pretty much anywhere.
    • DISM.exe /Apply-Image /ImageFile:Z:\install.wim /Index:1 /ApplyDir:E:\
    • Where Z: is the path where the backup image is stored and E: is the path of the partition to restore the image.
    •  If the image contains much data, it will take an amount of time proportional the amount of data and the throughput of your network, USB, or eSATA connection.  Be patient!

Wednesday, October 1, 2014

Create a New AD and SCCM 2012 User Collection with PowerShell

Function New-SCCMUserCollection {
PARAM (
[Parameter(Mandatory = $true)] $ADCollectionName,
                [Parameter(Mandatory = $true)] $CMCollectionName,
$limitingCollection = "All Users",
# Customize the $path appropriately for your environment.
$path = "OU=Application Deployment,OU=Groups,DC=<YourDomain>,DC=<YourNamespace>",
$description = "Application Deployment Group",
# Customize your domain name in the query.
$queryExpression = "select SMS_R_USER.ResourceID,SMS_R_USER.ResourceType,SMS_R_USER.Name,SMS_R_USER.UniqueUserName,SMS_R_USER.WindowsNTDomain from SMS_R_User where SMS_R_User.SecurityGroupName = '<YourDomain>\\$($ADCollectionName)'",
$ServerName = "<YourServerName>",
$SiteCode = "<YourSiteCode"
)
# Get a reference object for grabbing the RefreshSchedule property
        # Use an existing collection as a template to replicate the RefreshSchedule.
$refreshSchedule = (Get-CMDeviceCollection -Name "7zip").RefreshSchedule[0]
$ruleName = $CMCollectionName

# Create AD Security Group
New-ADGroup -Name $ADCollectionName -SamAccountName $ADCollectionName -GroupCategory Security -GroupScope Universal -DisplayName $ADCollectionName -Path $path -Description $description -Verbose

# Create SCCM Collection
New-CMUserCollection -Name $CMCollectionName -LimitingCollectionName $limitingCollection -Verbose -RefreshSchedule $refreshSchedule -RefreshType 2

# Add collection rule
    $CollectionName = Get-CMUserCollection -Name $CMCollectionName
    Add-CMUserCollectionQueryMembershipRule -CollectionId $CollectionName.CollectionID -RuleName $ruleName -QueryExpression $queryExpression -Verbose
}

# Import the Configuration Manager 2012 Module
Import-Module "C:\Program Files (x86)\ConfigMgr2012\bin\ConfigurationManager.psd1"
# Set location the primary site code
Set-Location <YourSiteCode>:
Import-Module ActiveDirectory

# Edit this variable to reflect the desired AD Security Group Names
$ADCollectionName = "Test User Collection"

# Do not edit this variable unless it is a special circumstance.
$CMCollectionName = "$ADCollectionName - User"

# Usage: New-SCCMUserCollection -ADCollectionName $ADCollectionName -CMCollectionName $CMCollectionName