SCCM PowerShell Task Sequence GUI

07 March, 2017

Playing around with our Task Sequences in SCCM I came to the realization that we have numerous post install tasks for optional software when an Imaged PC is for a particular department or entity. This is due to different departments having different software requirements. I started toying around with the idea of a software selection GUI as part of the Task Sequence that will allow customization of post install software in the aim to make all deployments ‘one touch’.


After some research and work I came up with a basic GUI with a few customization's:

undefined

However, this is still limited and does not cover all of our use cases, so we are still left with some post install tasks. After some more work I came up with the following ‘final’ GUI:

undefined

From this GUI we are able to choose all the combinations of required software for all departments and entities. No more post install tasks for any PC’s.


I had to do a few things to get this working as desired. But at the core of it, each of the tick boxes sets an MDT Task Sequence Variable. The variable weather ticked or not determines if the software installation step should proceed.

MDT Task Sequence Variables
The task sequence itself has some additional steps to create the variables. Each variable requires a separate step for the variable creation. I found the variables needed to be created in the task sequence before the PowerShell script that sets the variables values can be run.

undefined

All of the variable are set to False when created in the task sequence. The PowerShell script will later set the ones that are ticked to True.

undefined

 

Conditional Application Installations
We have the requirement that some applications are installed on every PC that we image, these applications are installed regardless of the options chosen. For the conditional application installations, I have created a separate step for each one.

undefined

Each of these steps simply installs a single application.

undefined

Under options I have set the condition that the Task Sequence Step only run if the corresponding variable is set to True.

undefined

 

The PowerShell Script
Creating GUI’s in PowerShell is tedious and annoying but there is plenty of information on how to do that so I will be glossing over the GUI creation part. The important part of the script is retrieving the value from the check box and injecting it into the Task Sequence variable. A minimal example how this works would be:

    #Get Variable from Form
    $installPDF = $pdfCheck.Checked #where $pdfCheck is the checkbox

    #set variable in the task sequence
    $TSEnv = New-Object -COMObject Microsoft.SMS.TSEnvironment 
    $TSEnv.Value("installPDFAnnotator") = "$($installPDF)"

The script needs to be made into an SCCM Package so that we can run the script from the Task Sequence. The source contents for the package should include the script to be run, ServiceUI.exe and any assets required by the script. In my case the company logo.

undefined

The package is nothing special, you only need to set the source files for it. And distribute it the required Distribution Points.

undefined

Incorporating the script into the task sequence requires adding a step ‘General > Run Command Line’. The command line step should look similar to the following:

undefined

The two main things to note here is the command line is pointing to the PowerShell script that is part of the package and that the package is selected. You just need to make sure that you declare all the MDT Task Sequence variables before running the PowerShell step “Prompt For Image Configuration”

undefined

And that should be it!

Office 365 Shared Mailbox Sent Items Folder

20 February, 2017

When creating a shared mailbox in Office 365 the default behaviour for items sent from this mailbox is odd. When a user who has access to the shared mailbox sends an item from or on behalf of the mailbox the item goes into the users ‘sent items’ folder. The sent item will not appear in the ‘sent items’ folder of the shared mailbox.

There is no obvious way to configure items sent from a shared mailbox to appear in the ‘sent items’ folder of the shared mailbox. This however can be configured quite easily from PowerShell. To do this you will first need to establish an Office 365 session in PowerShell. To establish a session:

Get Credentials

$cred = get-credential

Create a session with ps.outlook.com using the saved credentials

$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $cred -Authentication Basic -AllowRedirection 

Import the session

Import-PSSession $session -AllowClobber 

Once you have established the connection to Office 365 you can configure the ‘sent items’ behaviour or shared mailboxes.
To configure emails that are Sent As:

set-mailbox <mailbox name> -MessageCopyForSentAsEnabled $True

To configure emails that are sent of behalf of:

set-mailbox <mailbox name> -MessageCopyForSendOnBehalfEnabled $True

If you later want to stop the shared mailbox’s from saving sent items into their own ‘sent items’ folder, you can simple set the values in the commands above to $false instead of $true.

Adding Azure Remote App Users with PowerShell

16 February, 2017

Adding azure remote app users with PowerShell is a relatively simple task and many times quicker than waiting for the clunky web based UI. The first thing to do is install the ‘Microsoft Azure PowerShell module’.

Once you have this module installed you need to add an Azure account. You only ever need to do this once. It’s as simple as running the following cmdlet and signing in.

Add-AzureAccount

Once you have signed in you will need to select the subscription that you want to add the user to. You can get a list of all you subscriptions using:

Get-AzureSubscription

select a subscription use the following:

Select-AzureSubscription <Subscription Name>

Once you have selected your subscription you can begin to add users. This is as simple as running:

add-AzureRemoteAppUser -CollectionName <Collection Name> -Type orgid -Userupn <User UPN/Email>

This will then add the user to the selected collection under the selected subscription and allow them to start using remote apps.

SCCM 2012 R2 and PowerShell

14 February, 2017

To use PowerShell with SCCM you will all you need to do is import the module. If you don’t have the module installed you can get it from here: https://www.microsoft.com/en-us/download/details.aspx?id=46681 Note that you will also need to have Configuration Manager Console installed on your computer.

Once you have the module installed, import the module using the following command:

import-module "C:\Program Files (x86)\Microsoft Configuration \Manager\AdminConsole\bin\ConfigurationManager.psd1" 

Once you have imported the module you will need to connect to your site using the following:

CD X:

Where ‘x’ is your site code. In my case this is:

CD PR1: 

Once connected to your site you can query information about your site using:

get-cmsite

There are a whole bunch of cmdlets for SCCM that will allow you to do many tasks directly from the PowerShell console. I have a few SCCM scripts on my GitHub at: https://github.com/NathanKewley/Powershell_For_Dayz/tree/master/SCCM


As I create more scripts utilising SCCM I will be adding them to my Git. So far I have used PowerShell to query User and Device memberships from collections and export the results out to CSV’s for reporting.

Log Off an Azure Remote App User via PowerShell

15 November, 2016

I wrote this script because Azure Remote App is shit and always causes problems for users. One of the bigger problems is when a user’s application within Azure Remote App freezes, the user can’t simple restart the remote app as the server keeps the session and frozen/crashed application alive.

The solution to this is to log the user off the server. This module is designed to be a super simple way to log off a user just by using their email address that is associated with the Azure Remote App account.

function global:end-azureSession{
    Param(
        [parameter(HelpMessage='your username/email for azure')]
        [string]$userEmail,
        [parameter(HelpMessage='your password for azure')]
        [string]$cred
    )

    #define our set variables for the penrith enviroment
    $azureSubscription = 'PCC-AAE'

    #create credentials
    #$secPass = ConvertTo-SecureString $password -AsPlainText -Force
    if($cred){
        #$AzureCred = New-Object System.Management.Automation.PSCredential ($username, $secPass)
    }else{
        $cred = Get-Credential
        #$AzureCred = New-Object System.Management.Automation.PSCredential
    }
    #this will throw exception even if success.... so yep... this is my work-around...
    try{Add-AzureAccount -Credential $cred}catch{write-host "Connected to Azure" -ForegroundColor green}

    #Select subscription
    Select-AzureSubscription $azureSubscription

    #disconnect user
    write-host "Disconnecting user, this may take a while....." -ForegroundColor green
    try{
        invoke-AzureRemoteAppSessionLogoff -CollectionName rappaaeprod -UserUpn $userEmail -confirm:$false >$null 2>&1
        write-host "diconnected..." -ForegroundColor green
    }catch{
        $errorMessage = $_.Exception.Message
        if($errorMessage -eq "InternalError: The server encountered an internal error. Please retry the request."){
            write-host "User has been disconnected" -ForegroundColor green
        }else{
            write-host "ERROR: User connection to Azure not found" -ForegroundColor red
        }
    }
}

 

Example 1: this will prompt you for credentials then end the users session

end-azureSession Nathan.kewley@penrith.city

Example 2: You can save and pass credentials to the module

$cred = get-credential
end-azureSession Nathan.kewley@penrith.city $cred

 

 

12 Hour Game Jam

31 July, 2016

undefined

Yesterday I participated in my first ever game Jam in a team of 3 with Natasha Op't Land and Caleb Op't Land. The game jam was hosted by the University of Wollongong. For this game jam we had 12 hours to create A game fitting the theme that was announced on the day. The theme was: "Less is more, More is better".

We spent the first hour brainstorming and sketching out ideas for our game that could fit this theme. We came up with an idea to create a puzzle/maze like game from a top down perspective. But the unique aspect of our game was the decision to have 2 different realms co-exist on top of each other. The two realms would be the 'Overworld' and 'Underworld'.

undefined

Our plan was to create the Overworld in such a way that it appeared very minimal and simplistic, while the underworld would be busy and chaotic. So one realm would be less while the other is more. We decided that all of the hazards and traps in the maze would only be visible from the Underworld while the Overworld would appear as a simple, safe, peaceful place. The image below shows a comparison of the same level as viewed from the Overworld and Underworld. The player is able to switch between realms but can only stay in the Underworld for A limited amount of time.

undefined

Once we had decided on the game we were going to make and a few of the core mechanics we we were about an hour into the game jam. So with 11 hours left we were able to start building the game. Natasha began to design the look and feel of the game and would later create most of the graphics and spritesheets. Caleb began to create some level designs on paper that he would later make into real levels in the game. While I began to create a basic tile-map system that allowed us to have both realms co-exist with only one visible at any given time.

undefined

Once we had the tile-map system working Caleb was able to quickly recreate his sketches into real levels. And we could begin adding elements to the levels. By the end we had 4 different obstacles for the player to face as they progressed through the 8 levels Caleb managed to create. We had boxes to block the players movement, Lava that would kill the player, Portals that would send the player back to the beginning of the level and finally spike balls that would roll around the level and kill the player.

undefined

Towards the end of the jam to all of our surprise we actually had a little time left to go back and fix a few smaller issues that we had ignored in order to get the game to a state where it is complete. All in all I am very surprised in what we were able to achieve in only 12 hours and had a great time at the game jam. Thank to everyone at the University of Wollongong that made the jam happen!

You can play the game in your browser here: http://nathankewley.info/games/2016-UOW-Winter-Game-Jam/

You can download the source for the game here: https://github.com/NathanKewley/2016_UOW_Winter_Game_Jam

Home ← Older posts