Month: April 2014

ConfigMgr migration script – Disable non-limited OS of Package/Programs

Posted on Updated on

Let’s say you’ve just migrated hundreds of ConfigMgr packages where the Program(s) of those packages were not previously limited. Meaning that they were set to be able to run on any and every system … including servers. That could potentially cause a HUGE outage with significant consequences in the case of an administrative goof.  Ideally in this situation, you would want/need to limit those package to the proper OS (such as All Win7 x64).

Unfortunately there are no PowerShell cmdlets that can set the OS limiting of a Program/Package.  So as a safety precaution the below PowerShell script can be used to disable any Program of migrated Packages if the Program was not limited.  In this way it can give an admin the opportunity to manually remediate the Program configuration before an accident occurs!

# By https://t3chn1ck.wordpress.com

# Site Code + :
$SiteCode = "GAL"
Set-Location $SiteCode":"

clear
$ProgramArray = Get-CMProgram

ForEach ($Program in $ProgramArray){
    $OSCount = $Program.SupportedOperatingSystems.Count

    If ($OSCount.Equals(0)){
        $Program.ProgramFlags.ToString()

        if ($Program.PackageID.StartsWith($SiteCode)){
            # Do nothing
            Write-Host "Skipping non-migrated package " $Program.PackageName -ForegroundColor DarkYellow

        } ElseIf (($Program.ProgramFlags -band 0x00001000)) {
            # Program already disabled
            # Bitwise ProgramFlags operator found at http://msdn.microsoft.com/en-us/library/hh949572.aspx
            Write-Host "Skipping disabled program " $Program.PackageName -ForegroundColor DarkYellow

        } Else {
            Write-Host "No OS limits on active package " $Program.PackageName  -ForegroundColor Red
            #Disable-CMProgram -PackageId $Program.PackageID -ProgramName $Program.ProgramName
            Write-Host "Disabled Program: " $Program.ProgramName
        }

    } Else {
        Write-Host $OSCount " OS limits set for " $Program.PackageName " : " $Program.ProgramName -ForegroundColor DarkGreen
    }

    Write-Host "============="
}
Advertisement

ConfigMgr migration script – Change limiting collections

Posted on Updated on

When doing a migration of ConfigMgr, it could be handy to bulk convert collections that were migrated and need a new limiting collection. The below code example checks the last modified date of the collection … and if it was changed “today” (date when the script executes), then it will set the collection to have a new limiting collection. In this example, it was setting the limiting collection to one that I had created for All Windows Workstation Clients.

# https://t3chn1ck.wordpress.com

# Site code of primary (e.g. GAL:)
Set-Location "GAL:"

# Increase the max number of collection as follows
Set-CMQueryResultMaximum 300

# Collection ID of the new limiting collection
$LimitingCollection = "GAL00003"

# Build array of all collections
$CollArray = Get-CMDeviceCollection

# Get today's date to convert collections created TODAY
# If needing to do date other than TODAY, then set static string value as MM/DD/YYYY
$Today = get-date -format d
Write-Host "Today's date: " $Today

ForEach ($Collection in $CollArray){
# Get collection ID and creation date
$CollID = $collection.CollectionID
$CollDate = $Collection.LastChangeTime.Date.ToShortDateString()

If ($CollID.StartsWith("SMS")) {
# No need to convert "out of box" collections
Write-Host "Skipped SMS Pkg ID: " $CollID -f DarkYellow
} Else {
If ($CollDate.Equals($Today)) {
If ($Collection.LimitToCollectionID.Equals($LimitingCollection)) {
# Already converted if limiting collection already matches
Write-Host "Limiting collection already set for: " $Collection.Name

} Else {
# Date match of collection with today to be converted
Set-CMDeviceCollection -CollectionId $Collection.CollectionID -LimitingCollectionId $LimitingCollection
Write-Host "Set new limiting collection for: " $Collection.Name -ForegroundColor Green
}
} Else {
# Dates that do not match today should not be converted
Write-Host "Mismatch date: " $CollDate " for " $Collection.Name -f DarkRed
}
}
}

Common IA64 .inf file names

Posted on Updated on

Since Itanium (IA64) drivers cannot be migrated from ConfigMgr 2007 into 2012, I was looking for a way to easily exclude the drivers. I considered various options and ideally I wanted a simple column that would display the Applicability > Supported Platforms.  Alas, it was not that easy.  So the best easiest route that I could come up with on short notice was to add the Drivers column for INF, and then filter based upon common IA64 .inf file names.  Below is my short list which I hope to maintain as I discover new names!

Common IA64 (ending) INF file names

  1. 645.inf
  2. 6451.inf
  3. 6064.inf
  4. 5164.inf
  5. w64.inf

For example:

INF_Example

 

Fixes to Microsoft Package Source Conversion Scripts

Posted on Updated on

The Microsoft PFE team blog (ConfigMgr Dogs) has a very good sample scripts  for converting Package source files to a new location.  Located from http://blogs.technet.com/b/configmgrdogs/archive/2013/05/09/package-amp-application-source-modification-scripts.aspx

However, I have found a couple of logical bugs.  The first is that when using the command “Set-CMPackage -Name $Package.Name -Path $ChangePath”, this will cause ALL packages with the same name to be converted over to the same value as listed by $ChangePath .  Instead of using parameter “-Name $Package.Name”, this code needs to use “-Id $Package.PackageID”.

There second and confirmed logical bug if that is caused by the package path being case sensitive such that the conversion of $OldPath to $NewPath fails (no errors generated).

Finally, as an enhancement, it would be good for packages that have already been converted to not be run again.

Below is my rendition of the script


# Original script from
# http://blogs.technet.com/b/configmgrdogs/archive/2013/05/09/package-amp-application-source-modification-scripts.aspx
# Modifications by https://t3chn1ck.wordpress.com

Write-Host "#######################################################################"
Write-Host "##        Matts ConfigMgr 2012 SP1 Package Source Modifier           ##"
Write-Host "##                blogs.technet.com/b/ConfigMgrDogs                  ##"
Write-Host "#######################################################################"

# Site Code + :
Set-Location "S01:"

$PackageArray = Get-CMPackage
$OldPath = "\\2007SERVER\source$"
$NewPath = "\\2012SERVER\cmsource$"

ForEach ($Package in $PackageArray){
   $OldPkgPath = $Package.PkgSourcePath.ToLower()

   If ($OldPkgPath.StartsWith("\\2007server")){
      $ChangePath = $Package.PkgSourcePath.ToLower()
      $ChangePath = $ChangePath.Replace($OldPath, $NewPath)

      Set-CMPackage -Id $Package.PackageID -Path $ChangePath
      Write-Host "Changed: " $Package.Name " to " $ChangePath -f Green
   } Else {
      Write-Host "Not changed: " $Package.Name -f DarkYellow
   }
}

Script to check/kill process before install

Posted on Updated on

The following batch file can be used as an example of how to do a software installation/upgrade when process X is not running.  Note that also requires using PsKill from SysInternals.  The script will:

  1. Check for the existence of a running process (.exe) of the software
  2. Stop the process if detected as running
  3. Perform a software installation
  4. Then start the software again

@echo off
Set CURPATH = %~dp0

tasklist | findstr /i screenagent.exe
echo errorlevel = %ERRORLEVEL%
if ERRORLEVEL 0 goto Running
if ERRORLEVEL 1 goto DoInstall

:exit
exit 0

:DoInstall
echo Installing NICE ScreenAgent Software...
start /wait /i "NICE Agent" "%CURPATH%Setup.exe"
start ScreenAgent.exe
goto exit

:Running
echo ScreenAgent Running: stopping execution
"%CURPATH%pskill.exe" /accepteula ScreenAgent.exe
goto DoInstall