Author Archive | Jonathan

How to use the Query XML Activity in Orchestrator

In this post I will demonstrate how to get the information from inside a XML “tag” with the Orchestrator Activity “Query XML”. To exemplify this I will use the sample XML code below.

 <UserInputs>
  <UserInput Question=”Service Request to change Affected User at” Answer=”&lt;Values Count=&quot;1&quot;&gt;&lt;Value DisplayName=&quot;SR2086 – Default Service Request&quot; Id=&quot;fc9a9841-3e88-cbf3-43dc-1f27cbab680d&quot; /&gt;&lt;/Values&gt;” Type=”System.SupportingItem.PortalControl.InstancePicker” />
  <UserInput Question=”New Affected User” Answer=”&lt;Values Count=&quot;1&quot;&gt;&lt;Value DisplayName=&quot;Jonathan Andersson&quot; Id=&quot;cc40a4b6-b281-34a4-ced7-c27a4677fb9c&quot; /&gt;&lt;/Values&gt;” Type=”System.SupportingItem.PortalControl.InstancePicker” />
</UserInputs>

I will demonstrate how to get the “Question” text and pass it into a text file with Orchestrator.

The XPath Query I will use looks as this: /UserInputs/UserInput/@Question

The example Runbook

How to use the Query XML Activity in Orchestrator1

How to use the Query XML Activity in Orchestrator2

How to use the Query XML Activity in Orchestrator3

The result in the text file

How to use the Query XML Activity in Orchestrator4

 

When developing XPath Queries, freeformmatter.com is a nice place to try them at.

0

Configuration Manager 2012 SP1 Find Package from ID with PowerShell

If all you have is the packade ID and want to find out what packade it is you can use this PowerShell script below. 

Save the script as “FindPackage.ps1”, change the variables and run it as the following example:
“FindPackage.ps1 -Id P0100001”

It will return something like this.

Configuration Manager 2012 SP1 Find package from ID with PowerShell

PowerShell Script

Param
(
[Parameter(Mandatory=$True)]
[String]$Id
)
Process
{
# Variables
$CMSiteCode = “P01”
$CMModule = ‘C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1’
$PWDBegin = $PWD
$Find = $FALSE
 
Import-Module $CMModule
$CMSiteCode = $CMSiteCode + “:”
Set-Location $CMSiteCode
 
$ProgramPackageInfo = get-CMPackage -Id $Id
$DriverPackageInfo = get-CMDriverPackage -Id $Id
 
If ($ProgramPackageInfo -ne $NULL)
{
“”
“******************************************”
“This is a Program Package:”
“Package Name: ” + $ProgramPackageInfo.Name
“Package Source Path: ” + $ProgramPackageInfo.PkgSourcePath
“Source Date: ” + $ProgramPackageInfo.SourceDate
“******************************************”
“”
$Find = $TRUE
}
 
If ($DriverPackageInfo -ne $NULL)
{
“”
“******************************************”
“This is a Driver Package:”
“Package Name: ” + $DriverPackageInfo.Name
“Package Source Path: ” + $DriverPackageInfo.PkgSourcePath
“Source Date: ” + $DriverPackageInfo.SourceDate
“******************************************”
“”
$Find = $TRUE
}
 
If ($Find -eq $FALSE)
{
“”
“******************************************”
“No package found”
“******************************************”
“”
}
 
Set-Location $PWDBegin
}

Download

FindPackage

3

Configuration Manager 2012 Create Collection OS Structure with PowerShell

For creating Operating System Collections create a “CreateCollection.ps1” file and paste the PowerShell code below in the file (or download the file below). If needed change the variables $CMSiteCode and $CMModule in the script.

This will create the following structur.

Configuration Manager 2012 Create Collection OS Structure with PowerShell

# Variables
$PWDBegin=$PWD
$CMSiteCode=“P01” # Change this – This should be your site code
$CMModule=‘C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1’ # Change this – This should point to the CM module
Import-Module$CMModule
$CMSiteCode=$CMSiteCode+“:”
Set-Location$CMSiteCode
New-CMDeviceCollection-Name“Windows 8”-LimitingCollectionId“SMS00001”
Add-CMDeviceCollectionQueryMembershipRule-CollectionName“Windows 8”-QueryExpression“select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier, SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where sms_R_System.Operating_System_Name_and0 like ‘%Microsoft Windows NT Workstation 6.2%'”-RuleName“Windows 8”
New-CMDeviceCollection-Name“Windows 7”-LimitingCollectionId“SMS00001”
Add-CMDeviceCollectionQueryMembershipRule-CollectionName“Windows 7”-QueryExpression“select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier, SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where sms_R_System.Operating_System_Name_and0 like ‘%Microsoft Windows NT Workstation 6.1%'”-RuleName“Windows 7”
New-CMDeviceCollection-Name“Windows Vista”-LimitingCollectionId“SMS00001”
Add-CMDeviceCollectionQueryMembershipRule-CollectionName“Windows Vista”-QueryExpression“select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier, SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where sms_R_System.Operating_System_Name_and0 like ‘%Microsoft Windows NT Workstation 6.0%'”-RuleName“Windows Vista”
New-CMDeviceCollection-Name“Windows XP”-LimitingCollectionId“SMS00001”
Add-CMDeviceCollectionQueryMembershipRule-CollectionName“Windows XP”-QueryExpression“select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier, SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where sms_R_System.Operating_System_Name_and0 like ‘%Microsoft Windows NT Workstation 5.1%'”-RuleName“Windows XP”
New-CMDeviceCollection-Name“Windows Server 2012”-LimitingCollectionId“SMS00001”
Add-CMDeviceCollectionQueryMembershipRule-CollectionName“Windows Server 2012”-QueryExpression“select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier, SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where sms_R_System.Operating_System_Name_and0 like ‘%Microsoft Windows NT Server 6.2%'”-RuleName“Windows Server 2012”
New-CMDeviceCollection-Name“Windows Server 2008 R2”-LimitingCollectionId“SMS00001”
Add-CMDeviceCollectionQueryMembershipRule-CollectionName“Windows Server 2008 R2”-QueryExpression“select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier, SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where sms_R_System.Operating_System_Name_and0 like ‘%Microsoft Windows NT Server 6.1%'”-RuleName“Windows Server 2008 R2”
New-CMDeviceCollection-Name“Windows Server 2008”-LimitingCollectionId“SMS00001”
Add-CMDeviceCollectionQueryMembershipRule-CollectionName“Windows Server 2008”-QueryExpression“select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier, SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where sms_R_System.Operating_System_Name_and0 like ‘%Microsoft Windows NT Server 6.0%'”-RuleName“Windows Server 2008”
New-CMDeviceCollection-Name“Windows Server 2003”-LimitingCollectionId“SMS00001”
Add-CMDeviceCollectionQueryMembershipRule-CollectionName“Windows Server 2003”-QueryExpression“select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier, SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where sms_R_System.Operating_System_Name_and0 like ‘%Microsoft Windows NT Server 5.2%'”-RuleName“Windows Server 2003”
Set-Location$PWDBegin

Download the script: CreateCollections

0

Configuration Manager 2012 Add App-V Application with Powershell

I had the need to add a few App-V applications to my Configuration Manager environment and created a script to simplify this. The script will extract information from the App-V manifest XML file and use the application name and application version when adding the application to the SCCM. The script will also create a deployment type to the SCCM application.

To run the script just execute the following command in a PowerShell shell:
AddCMAppV.ps1 –APPFilePath ‘\\SCCM\PKG\App1\app1_manifest.xml’

PowerShell script

Param(
    [Parameter(Mandatory=$True)]
    [String]$APPFilePath
)
Process
{
    # Variables
    $Manufacturer = “”
    $ProductVersion = “”
    $ProductName = “”
    $PWDBegin = $PWD
    $CMSiteCode = “P01” # Change this – This should be your site code
    $CMModule = ‘C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1’ # Change this – This should point to the CM module
 
    $APPFileName = $APPFilePath.split(“\”)[-1]
    Write-Host “FileName: ” $APPFileName
 
    If ($APPFileName.split(“.”)[-1].ToLower() -ne “xml”)
    {
        Write-Host “ERROR – The file “”$APPFileName”” is not a XML file”
        Break
    }
    If ((Test-Path $APPFilePath) -eq $False)
    {
        Write-Host “ERROR – The path “”$APPFilePath”” is not correct”
        Break
    }
   
    # Get AppV information
    $AppInfo = Get-Content $APPFilePath
    $AppName = $AppInfo.PACKAGE.APPLIST.APP.NAME
    $AppVersion = $AppInfo.PACKAGE.APPLIST.APP.VERSION
   
    Import-Module $CMModule
    $CMSiteCode = $CMSiteCode + “:”
    Set-Location $CMSiteCode
   
    If ((Get-CMApplication -Name “$AppName $AppVersion”) -ne $NULL)
    {
        Write-Host “ERROR – CM Application with name “”$AppName $AppVersion”” already exist”
    }
    Else
    {
        Write-Host “Adding CM Application: “”$AppName $AppVersion”””
        New-CMApplication -Name “$AppName $AppVersion” -SoftwareVersion $AppVersion
    }   
   
    If ((Get-CMDeploymentType -ApplicationName “$AppName $AppVersion” -DeploymentTypeName $AppName) -ne $NULL)
    {
        Write-Host “ERROR – CM Deployment Type with name “”$AppName”” already exist”
        Set-Location $PWDBegin
        Break
    }
    Else
    {
        Write-Host “Adding CM Deployment Type: “”$AppName”””
        Add-CMDeploymentType -ApplicationName “$AppName $AppVersion” -DeploymentTypeName “$AppName” -AdministratorComment “Created by PowerShell” -InstallationFileLocation $APPFilePath -AutoIdentifyFromInstallationFile -ForceForUnknownPublisher $True -AppvInstaller
    } 
    Set-Location $PWDBegin
}

Add many applications to SCCM 2012

To add more than one application just create a CMD file with the following information and put in the same directory as the PowerShell script file.

powershell.exe .\AddCMAppV.ps1 -APPFilePath ‘\\SCCM201201\Apps$\App-V\Skype 5.5.32.124\Skype_V5\Skype_V5_manifest.xml’
powershell.exe .\AddCMAppV.ps1 -APPFilePath ‘\\SCCM201201\Apps$\App-V\Firefox\firefox.001\firefox.001_manifest.xml’

1