Post Upgrade Task Sequence Payload to User

Profile picture for user PaulW
Posted by PaulW on Wed, 02/13/2019 - 06:53pm

For part of our upgrade process, we decided that we wanted to give users the opportunity to complete a survey to give us their feedback on the upgrade process.  We thought of an email but, figured that would be just as well ignored as any other bulk email.  So, I thought we could just dump something in the run once, or startup for the user that initiated the upgrade.  So, the first thing I needed to do was capture the user to a task sequence variable.  Sounds easy but, remember, the task sequence runs as system.

Garytown.com posted a similar process a few weeks ago.  Similar process, executed for different reasons, and executed with a different script. 

So, did some searching (Gary's blog wasn't there yet) and tried a few other scripts that didn't get the job done.  Then I thought of a tool that I use every day (well, quite often anyway) that logs the user account of the active session into its excellent CMTrace style logging.  This tool, of course, is the PowerShell App Deployment Toolkit.  So, doing a little deconstruction of the toolkit, I found where the user information was being discovered.  So, I came up with this:

Get-ConsoleUserToVariable.ps1

$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
[string[]]$ReferencedAssemblies = 'System.Drawing', 'System.Windows.Forms', 'System.DirectoryServices'
Add-Type -Path "$scriptPath\AppDeployToolkitMain.cs" -ReferencedAssemblies $ReferencedAssemblies
$user=[PSADT.QueryUser]::GetUserSessionInfo("$env:ComputerName")
try{
    $tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment
    $tsenv.Value("ConsoleUser") = "$($user.UserName)"
    }
catch{
    Write-host "Not running a TS.  Would set variable [ConsoleUser] to [$($User.UserName)]"
    }

So, download the latest PSADT and grab the AppDeployToolkitMain.cs file from the AppDeployToolkit directory.  Put this with the above script into a package.  Then, add a task sequence step early in the task sequence that runs Get-ConsoleUserToVariable.ps1.

Now that I have the user in the variable ConsoleUser, I can use it later on in the task sequence....

Meanwhile, later on in the task sequence....  Ok, so right before the task sequence is completed, I want to drop my payload in the user's startup folder.  That way, our survey launches and completes.

Survey Launcher TS Step

The batch files is a self deleting execution of IE to open the survey web page.  It launches IE and then deletes itself.

I wouldn't call this a perfect solution.  And I don't need it to be.  There is always the chance that the person that starts the TS may not be the person to log in after the upgrade is complete.  This among other possible scenarios could occur.  But again, I don't need this to be perfect, I just want it to work most of the time.

Related Technology

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
Verify you are a human.