25 jun 2013

SCCM by Davis: “Convert ConfigMgr Applications to MDT Applications with PowerShell” plus 19 more

SCCM by Davis: “Convert ConfigMgr Applications to MDT Applications with PowerShell” plus 19 more

Link to SCCM by Davis

Convert ConfigMgr Applications to MDT Applications with PowerShell

Posted: 29 Apr 2013 07:41 AM PDT

For those of you who have ever attended one of Johan Arwidmark's talks or classes on OS deployment, you were probably convinced, like me, to capture your reference image using MDT LiteTouch for deployment with ConfigMgr. There are several advantages to capturing your reference image with LiteTouch (speed, compatibility, delegation, features) and there can also be a few disadvantages. One of those is if you have a thick or fat image, i.e. you have a lot of applications installed in your reference image.

Most of the applications you have in your MDT environment need to be maintained in your Configuration Manager environment as well, so that you can deploy the latest versions to your SCCM clients. So, when the time comes to update your reference image, you need to create all of those applications again in MDT.

Enter the "Convert-CMApptoMDTApp" PowerShell script. This script converts applications created in ConfigMgr 2012 SP1 to MDT applications. It utilises the new Configuration Manager 2012 SP1 and MDT 2012 PowerShell modules.

To create an application in MDT, we need a few bits of information:

Name, ShortName, Version, SoftwareVersion, Publisher, Language, CommmandLine, WorkingDirectory, ApplicationSourcePath, DestinationFolder

These can be retrieved from the the ConfigMgr application using the Get-CMDeploymentType cmdlet. We get the latest revisions by specifying the IsLatest property = True.

The Get-CMDeploymentType cmdlet is a strange fish and I had to play around with it quite a bit to understand the information it returns.

When you run the Get-CMDeploymentType cmdlet using the -ApplicationName parameter, you get back an array of deployment types. Each deployment type has a property called SDMPackageXML, which contains most of the interesting information that we need. Firstly, we need to convert this object from XML using the [Microsoft.ConfigurationManagement.ApplicationManagement.Serialization.SccmSerializer]::DeserializeFromString() method so that we can easily access its properties.

Now, each SDMPackageXML object has a property called DeploymentTypes. If you have an application with one Deployment type, the DeploymentTypes property will return information about that one deployment type. However, things start to get a little confusing when you have multiple deployment types for an application.

Let me explain.

1. You have an Application called App1, with a deployment type DT1, which has a version of V1. You run the Get-CMDeploymentType cmdlet. It returns one deployment type. The DeploymentTypes property of that deployment types returns information about DT1 v1.

2. You add a second deployment type to App1, called DT2 v1. You run the Get-CMDeploymentType cmdlet. It returns two deployment types. The DeploymentTypes property of DT1 returns information about DT1. The DeploymentTypes property of DT2 returns information about DT1 v1 and DT2 v1.

3. You make a change to deployment type DT1 v1 – it is now v2. You run the Get-CMDeploymentType cmdlet. It returns two deployment types. The DeploymentTypes property of DT1 returns information about DT1 v2 and DT2 v1. The DeploymentTypes property of DT2 returns information about DT1 v1 and DT2 v1.

So, to summarise the behaviour of the cmdlet when there are multiple deployment types: The most recently modified deployment type contains the most up-to-date information about all deployment types for that application, while less recently modified deployment types contain information about themselves and the versions of other deployment types that existed when they were modified. Weird, huh?

So, to make sure we look at the most recent version of a deployment type in the DeploymentTypes property for that specific deployment type, we need to compare the ID and version of the deployment type using the CI_UniqueID property and the DeploymentTypes.ID property:

    Compare-Object -ReferenceObject $dtUniqueID -DifferenceObject $dtInstance.ID -IncludeEqual -Property Name,Version | Where { $_.SideIndicator -eq "==" }    

Another issue I encountered is that MDT won't create applications with the same name or destination folder, but multiple deployment types can share the same application name and different applications might have deployments types with the same name. So we need to append a number to each duplicate application name to ensure they are unique.

Here's a nice one-liner that takes care of this problem:

    $cmAppDT | Group-Object -Property Name -ErrorAction SilentlyContinue | Where { Foreach-object { $_.count -gt 1; $i=1} } -ErrorAction SilentlyContinue  | Select Group -ExpandProperty Group -ErrorAction SilentlyContinue | Foreach-object { Add-Member -InputObject $_ -membertype NoteProperty -name Name -value ($_.Name + "_" + $i) -Force -ErrorAction SilentlyContinue; Add-Member -InputObject $_ -membertype NoteProperty -name DestinationFolder -value ($_.DestinationFolder + "_" + $i) -Force -ErrorAction SilentlyContinue; $i++  }    

If you have two deployment types that share the same application name "Application", these will be renamed Application_1 and Application_2.

Now that we have those small details out of the way, let's see the script in action.

The script will get a list of all of your CM12 applications and display the list using the Out-GridView cmdlet. This lets you select the applications you want to convert.

CMApps

Once you have selected the applications for conversion, the script runs the Get-CMDeploymentType cmdlet against each one and displays a progress indicator. This can take some time, depending on how many applications you have selected.

DT1

It will only look at MSI and Script deployment types, extract all the necessary information to create an application in MDT and then display the list of deployment types, again using the Out-GridView cmdlet. This lets you select the deployment types you want to convert.

MDTApps

Once you have selected the deployment types for conversion, they are passed to the Import-MDTApplication cmdlet to be created in MDT.

MDTImport

Script Pre-requisites:

Appropriate permissions in ConfigMgr and MDT.
The Configuration Manager 2012 SP1 PowerShell Module is expected in this directory:
"C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1″
The MDT 2012 PowerShell Module is expected in this directory:
"C:\Program Files\Microsoft Deployment Toolkit\bin\MicrosoftDeploymentToolkit.psd1″

Running the script:

To run the script, save it as "Convert-CMApptoMDTApp.ps1″. Launch a PowerShell (x86) console as administrator. You can set the values of the parameters in the script, or you can run the script with parameters, e.g.

Convert-CMApptoMDTApp.ps1 -CMSiteCode "CM1″ -CMSiteServer "CMServer1″ -MDTSharePath "\\MDTServer1\MDTShare" -MDTAppFolderName "CMApps"

The script:

    Param (      [ValidateNotNullOrEmpty()]      [string]$CMSiteCode = "CM1",      [ValidateNotNullOrEmpty()]      [string]$CMSiteServer = "CMServer",      [ValidateNotNullOrEmpty()]      [string]$MDTSharePath = "\\MDTServer\MDTShare",      [ValidateNotNullOrEmpty()]      [string]$MDTAppFolderName = "CMApps"  )    # Import CM12 and MDT 2012 PowerShell modules  Import-Module "C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1"  Import-Module "C:\Program Files\Microsoft Deployment Toolkit\bin\MicrosoftDeploymentToolkit.psd1"    # Set the working directory to the CM Site code  CD ($cmSiteCode + ":")    # Get a list of all CM applications  $cmApps = Get-WmiObject -ComputerName $cmSiteServer -Namespace "Root\SMS\Site_$cmSiteCode" -Query "Select LocalizedDisplayName from SMS_Application Where IsLatest='True'" | Sort LocalizedDisplayName  # Output the list of applications to a Grid to allow browsing and selecting of the CM Apps to be converted to MDT Apps.  $cmApps = $cmApps | Out-GridView -PassThru    # Array to hold all of the CM deployment types  $cmAppDT = @()  # Counter for the progress of CM App processing.  $cmAppIndicator = 0  # Counter for the progress of conversion to MDT Apps.  $mdtAppIndicator = 0    If ($cmApps -ne $null) {      Foreach ($cmApp in $cmApps) {          $cmAppsCount = @($cmApps).Count          $cmAppIndicator++          Write-Progress -Activity "Processing Application $cmAppIndicator of $cmAppsCount" -Status $cmApp.LocalizedDisplayName -PercentComplete ($cmAppIndicator / $cmAppsCount * 100)            # Get a list of the deployment types for each application          $cmDeploymentType = Get-CMDeploymentType -ApplicationName ($cmApp | Select LocalizedDisplayName -ExpandProperty LocalizedDisplayName)            # Enumerate the latest deployment types and get the latest SDMPackageVersion          Foreach ($dt in $cmDeploymentType | Where { $_.IsLatest -eq $true }) {              $SDMPackageXML = $dt | Select SDMPackageXML -ExpandProperty SDMPackageXML              If ($dt.Technology -match "Script" -or $dt.Technology -match "MSI") {                  If ($SDMPackageXML -ne "") {                      $dtInfo = [Microsoft.ConfigurationManagement.ApplicationManagement.Serialization.SccmSerializer]::DeserializeFromString($SDMPackageXML)                      $dtCI_UniqueID = $dt.CI_UniqueID -split "/"                      $dtUniqueID = @()                      # Get the Deployment Type ID and version                      $dtUniqueID = New-Object PSObject -Property @{                          Name     =    $dtCI_UniqueID[1]                          Version =    $dtCI_UniqueID[2]                      }                      $dtInstances = $dtInfo.DeploymentTypes                      Foreach ($dtInstance in $dtInstances) {                          # Compare the DT ID and Version to those contained in the DeploymentTypes property to make sure we get the most recent version of the deployment type and only this deployment type in our ForEach loop.                          If ((Compare-Object -ReferenceObject $dtUniqueID -DifferenceObject $dtInstance.ID -IncludeEqual -Property Name,Version | Where { $_.SideIndicator -eq "==" } ) -ne $null ) {                              $dtInstaller = $dtInstance | Select Installer -ExpandProperty Installer                              If ($dtInstaller.Technology -match "Script" -or $dtInstaller.Technology -match "MSI") {                                  # If the working directory of the CM App is a local drive or environment variable, set the MDT App working directory accordingly                                  If ($dtInstaller.InstallFolder -match ":" -or $dtInstaller.InstallFolder -match "%") {                                      $dtWorkingDirectory = $dtInstaller.InstallFolder                                  }                                  # Otherwise, set the MDT working directory to the root of the MDT application we are creating.                                  Else {                                      $dtWorkingDirectory = ".\Applications\" + $dtInfo.Title                                  }                                  # Create a custom PS object with the information from the CM App DT we need to create the MDT App                                  $cmAppDT += New-Object PSObject -Property @{                                      Name                    =     $dtInfo.Title                                      ShortName                =     $dtInstance.Title                                      Version                    =     $dtInfo.SoftwareVersion                                      Publisher                 =     $dtInfo.Publisher                                      Language                 =    ($dtInstance | Select Languages -ExpandProperty Languages) -join ","                                      CommandLine             =    $dtInstaller.InstallCommandLine                                      WorkingDirectory         =    $dtWorkingDirectory                                      ApplicationSourcePath    =    ($dtInstaller | Select Contents -ExpandProperty Contents | Select Location -ExpandProperty Location)                                      DestinationFolder         =    $dtInfo.Title                                  }                              }                          }                      }                  }                  Else {                      $dtName = $dt.LocalizedDisplayName                      Write-Host "$dtName has no SDMPackage information"                  }              }          }      }        If ($cmAppDT -ne $null) {            # Multiple deployment types can share the same application name and different applications might have deployments types with the same name.          # MDT won't allow applications with the same name or destination folder, so we need to append a number to each duplicate deployment type to ensure they are unique.          $cmAppDT | Group-Object -Property Name -ErrorAction SilentlyContinue | Where { Foreach-object { $_.count -gt 1; $i=1} } -ErrorAction SilentlyContinue  | Select Group -ExpandProperty Group -ErrorAction SilentlyContinue | Foreach-object { Add-Member -InputObject $_ -membertype NoteProperty -name Name -value ($_.Name + "_" + $i) -Force -ErrorAction SilentlyContinue; Add-Member -InputObject $_ -membertype NoteProperty -name DestinationFolder -value ($_.DestinationFolder + "_" + $i) -Force -ErrorAction SilentlyContinue; $i++  }            # Output the Deployment Types to a Grid to allow browsing and selecting of the CM Apps to be converted to MDT Apps.          $cmAppDTsToConvertToMDTApps = $cmAppDT | Sort -Property Name | Out-GridView -PassThru            If ($cmAppDTsToConvertToMDTApps -ne $null) {              $mdtAppCount = @($cmAppDTsToConvertToMDTApps).Count              # Create a new PSDrive pointing to the MDT share              New-PSDrive -Name "DS001" -PSProvider MDTProvider -Root $mdtSharePath | Out-Null              # Create a folder under the MDT Applications folder for our imported CM applications.              If (!(Test-Path (Join-Path "DS001:\Applications" $MDTAppFolderName))) {                  New-Item -path "DS001:\Applications" -Enable "True" -Name $MDTAppFolderName -Comments "Applications Converted From System Center Configuration Manager" -ItemType Folder | Out-Null              }              # Import each selected application in to MDT              Foreach ($mdtApp in $cmAppDTsToConvertToMDTApps ) {                  $mdtAppIndicator++                  Write-Progress -Activity "Processing Application $mdtAppIndicator of $mdtAppCount" -Status $mdtApp.Name -PercentComplete ($mdtAppIndicator / $mdtAppCount * 100)                  Import-MDTApplication -path "DS001:\Applications\$MDTAppFolderName" -enable "True" -Name $mdtApp.Name -ShortName $mdtApp.ShortName -Version $mdtApp.Version -Publisher $mdtApp.Publisher -Language $mdtApp.Language -CommandLine $mdtApp.CommandLine -WorkingDirectory $mdtApp.WorkingDirectory -ApplicationSourcePath $mdtApp.ApplicationSourcePath -DestinationFolder $mdtApp.DestinationFolder              }          }      }  }    

PowerShell is King – Using PowerShell in a Task Sequence – Part 1

Posted: 23 Apr 2013 09:40 PM PDT

Traditionally VBscript has been "the" script type to use in OS Deployment scenarios, but with WinPE 4.0 in the ADK and MDT 2012 (u1) it is now an option in some scenarios.

Scenario:

You would like to use a PowerShell script that uses properties from the ZTIGather process

Solution:

Create the script and save it in the scripts folder in the deployment share (LTI) or in the MDT packages folder (ZTI) and then add it to the Task Sequence and if needed add any parameters you need to pass to the script. You don't need to add any parameters from the LTI/ZTI environment, since they will be available within $TSenv:

image

The script:

Here is just a demo script that does not do anything at all, but it should give you an idea of how to create those scripts.


#Demo.ps1

#Setting
$ScriptFile = $MyInvocation.MyCommand.Name
$ScriptLocation  = Split-Path $MyInvocation.MyCommand.Path -Parent

#Setting Vars
$OSDComputername = $TSEnv:OSDCOMPUTERNAME
$Make = $TSEnv:Make
$Model = $TSEnv:Model

#Performing Action
Write-Progress -Activity "Checking Hardware…" -Status "Running Inventory" -PercentComplete 12 -Id 1
Start-Sleep -Seconds 3

Write-Progress -Activity "Checking Hardware…" -Status "Running $ScriptFile" -PercentComplete 12 -Id 1
Start-Sleep -Seconds 3

Write-Progress -Activity "Checking Hardware…" -Status "Running $ScriptLocation" -PercentComplete 12 -Id 1
Start-Sleep -Seconds 3

Write-Progress -Activity "Checking Hardware…" -Status "Make is now $Make" -PercentComplete 32 -Id 1
Start-Sleep -Seconds 3

Write-Progress -Activity "Checking Hardware…" -Status "Model is now $MODEL" -PercentComplete 85 -Id 1
Start-Sleep -Seconds 3

Write-Progress -Activity "Checking Hardware…" -Status "Waiting when we are at 99% just because we can…" -PercentComplete 99 -Id 1
Start-Sleep -Seconds 3

Write-Progress -Activity "Checking Hardware…" -Status "Done" -PercentComplete 100 -Id 1
Start-Sleep -Seconds 3


 

Explaining the script:

The first block is just to set variables for the script it self, it s possible to use other methods, but I prefer to use the built-in method in PowerShell to find out where I am instead of using the translated way in LTI/ZTI

The next block is to show you how to convert a variable from the Task Sequence using the $TSEnv: drive. You don't need to do this, it is possible to use $TSEnv:OSDComputername directly, but I think this is a bit easier.

Remaining blocks will display the information on the screen while running.

Download Script

/mike

PORTS TO BE OPEN FOR SCCM 2012

Posted: 23 Apr 2013 06:51 AM PDT

sccm-ports

43.285400 5.376100

To CAS or Not to CAS

Posted: 22 Apr 2013 07:54 PM PDT

WHY Series #1 I figured I'd start the WHY Series with a question that will have an impact on your Co

Phil Wilcock started the forum topic SCCM2012 R2 Preview in the group System Center Configuration Manager 2012

Posted: 25 Jun 2013 02:31 AM PDT

RSAT for Windows 8.1 Preview available for download

Posted: 25 Jun 2013 02:51 AM PDT

Windows 8.1 Preview is not yet available for public or MSDN download, but RSAT for Windows 8.1 Preview is already available!

Download it here:
http://www.microsoft.com/en-us/download/details.aspx?id=39296

Windows 8.1 Preview should be available soon.

Windows Server 2012 R2 Preview–Ready for download on MSDN

Posted: 25 Jun 2013 02:15 AM PDT

System Center R2 Preview–Ready for download on MSDN

Posted: 25 Jun 2013 02:14 AM PDT

Microsoft and Oracle announce enterprise partnership

Posted: 25 Jun 2013 01:30 AM PDT

Deal will help customers embrace cloud computing by providing greater choice and flexibility. Microsoft Corp. and Oracle Corp. today announced a partnership that will enable customers to run Oracle software on Windows Server Hyper-V and in Windows...

Continue at Bink.nu Website!

Evaluation Guide for System Center 2012 R2 and the Windows Azure Pack

Posted: 25 Jun 2013 01:28 AM PDT

This documentation provides the information to help you set up and test an evaluation environment for tenant and administrator portals. The Evaluation Guide for System Center 2012 R2 and the Windows Azure Pack is designed for hosting providers and...

Continue at Bink.nu Website!

Database as a Service Reference Architecture Guide

Posted: 25 Jun 2013 01:27 AM PDT

Provides hardware, software, system design, and component configurations to create secure, scalable, distributed, multitenant database services that use the latest virtualization technologies. This guidance is targeted at hosting providers who...

Continue at Bink.nu Website!

Windows Azure Infrastructure Services Poster

Posted: 25 Jun 2013 01:25 AM PDT

The poster depicts common scenarios for Windows Azure Infrastructure Services. Click to download poster

Continue at Bink.nu Website!

Desktop Hosting Reference Architecture Guide

Posted: 25 Jun 2013 01:23 AM PDT

Defines how to create secure, scalable, and reliable desktop hosting solutions for small- and medium-sized organizations based on Remote Desktop Services, Hyper-V, virtual networking, and other virtualization technologies.  Download

Continue at Bink.nu Website!

Remote Server Administration Tools for Windows 8.1 Preview

Posted: 25 Jun 2013 01:23 AM PDT

Remote Server Administration Tools for Windows 8.1 Preview enables IT administrators to manage roles and features that are installed on computers that are running Windows Server 2012 or Windows Server 2012 R2 Preview from a remote computer that is...

Continue at Bink.nu Website!

Microsoft Integration Platform Poster

Posted: 25 Jun 2013 01:22 AM PDT

The poster depicts the MS integration platform, including enterprise integration with the cloud. Click picture to download

Continue at Bink.nu Website!

Windows Azure Pack for Windows Server

Posted: 25 Jun 2013 01:15 AM PDT

Windows Azure Pack for Windows Server is a collection of Windows Azure technologies, available to Microsoft customers at no additional cost for installation into your data center. It runs on top of Windows Server 2012 R2 and System Center 2012 R2...

Continue at Bink.nu Website!

Download Microsoft SQL Server 2014 Community Technology Preview 1 (CTP1)

Posted: 25 Jun 2013 01:13 AM PDT

Microsoft SQL Server 2014 brings to market new in-memory capabilities built into the core database, including in-memory OLTP, which complements our existing in-memory data warehousing and BI capabilities for the most comprehensive in-memory database...

Continue at Bink.nu Website!

Download Microsoft System Center 2012 R2 Configuration Manager and Endpoint Protection Preview

Posted: 25 Jun 2013 01:11 AM PDT

System Center 2012 R2 Configuration Manager helps IT empower people to use the devices and applications they need to be productive while maintaining corporate compliance and control. When combined with Windows Intune, it provides a unified...

Continue at Bink.nu Website!

Download Microsoft System Center 2012 R2 Preview

Posted: 25 Jun 2013 01:10 AM PDT

Microsoft System Center is a comprehensive IT infrastructure, virtualization, and cloud management platform. With System Center 2012 R2, you can more easily and efficiently manage your applications and services across multiple hypervisors as well as...

Continue at Bink.nu Website!

Download Windows Server 2012 R2 Preview

Posted: 25 Jun 2013 01:07 AM PDT

  Windows Server 2012 R2 provides a wide range of new and enhanced features and capabilities spanning server virtualization, storage, software-defined networking, server management and automation, web and application platform, access and...

Continue at Bink.nu Website!

No hay comentarios:

Publicar un comentario

SCCM by Davis