Tasbar Icons with Execute-ProcessAsUser issue

Hello,

I am creating an install of O365 Click to Run install and trying to customize taskbar icons on the fly. I have it most of the way there but there is one snafu. Our taskbar icons are set by GPO so I am removing the Office 2016 icons in pre install and attempting to add the O365 icons in post install.

The unpin script works fine and all of the Office 2016 icons are removed. Then Office installs just fine but the pin script doesn’t pin anything and the installation finished without error. If I go to the script and run it manually from powershell or right click it and “run with powershell” it works just fine and pins the icons. But never works through the PSADT install.

I am using the scripts from https://pinto10blog.wordpress.com/2016/09/10/pinto10/ to handle the pinning and unpinning.

Could this be an issue with running as the user two different times? Here is the meat of my deploy-application.ps1.

        $installdir = Get-ChildItem c:\windows\ccmcache\*\officecheck.txt -filter officecheck.txt | Select-Object -ExpandProperty directoryname` 

		$user = Get-LoggedOnUser

		new-item -Path c:\files\scripts -ItemType directory -force
		copy-item -Path $installdir\files\pin_pre1903.ps1 -Destination c:\files\scripts\pin_pre1903.ps1
		copy-item -Path $installdir\files\pin_1903.ps1 -Destination c:\files\scripts\pin_1903.ps1
		copy-item -Path $installdir\files\unpin_pre1903.ps1 -Destination c:\files\scripts\unpin_pre1903.ps1
		copy-item -Path $installdir\files\unpin_1903.ps1 -Destination c:\files\scripts\unpin_1903.ps1
		copy-item -Path $installdir\files\PinToTaskBar1903.ps1 -Destination c:\files\scripts\PinToTaskBarPre1903.ps1
		copy-item -Path $installdir\files\PinToTaskBar1903.ps1 -Destination c:\files\scripts\PinToTaskBar1903.ps1
		$win10version = (Get-Item "HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion").GetValue('ReleaseID')

		If ($win10version -ge 1903) {
			Execute-ProcessAsUser -UserName $user.username -Path "$PSHOME\powershell.exe" -Parameters "-Command & { & `"C:\files\scripts\unpin_1903.ps1`"; Exit `$LastExitCode }" -Wait
			}
			Else {
			Execute-ProcessAsUser -UserName $user.username -Path "$PSHOME\powershell.exe" -Parameters "-Command & { & `"C:\files\scripts\unpin_pre1903.ps1`"; Exit `$LastExitCode }" -Wait
			}
		
		
		##*===============================================
		##* INSTALLATION 
		##*===============================================
		[string]$installPhase = 'Installation'
		
		## <Perform Installation tasks here>
		Show-InstallationProgress -StatusMessage "Installing Microsoft Office 365 Pro Plus"  
		Execute-Process 'setup.exe' -Parameters '/configure configuration.xml' -WindowStyle Hidden
		
		##*===============================================
		##* POST-INSTALLATION
		##*===============================================
		[string]$installPhase = 'Post-Installation'
		
		## <Perform Post-Installation tasks here>

		If ($win10version -ge 1903) {
			Execute-ProcessAsUser -UserName $user.username -Path "$PSHOME\powershell.exe" -Parameters "-Command & { & `"C:\files\scripts\pin_1903.ps1`"; Exit `$LastExitCode }" -Wait
			}
			Else {
			Execute-ProcessAsUser -UserName $user.username -Path "$PSHOME\powershell.exe" -Parameters "-Command & { & `"C:\files\scripts\pin_pre1903.ps1`"; Exit `$LastExitCode }" -Wait
			}

The machine I am testing on is 1903 so here is the content of the pin_1903.ps1 script.

$path = 'c:\files\scripts\PinToTaskBar1903.ps1'
& $path 'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Outlook.lnk' PIN
& $path 'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Skype For Business.lnk' PIN
& $path 'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Word.lnk' PIN
& $path 'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Excel.lnk' PIN
& $path 'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Publisher.lnk' PIN
& $path 'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\PowerPoint.lnk' PIN

Are you testing this as a user-targeted deployment in SCCM, or testing directly in a lab?

Also, you’re missing a trailing } here, which may be an artifact of your copy-paste, but thought I’d double-check. We all make the simple mistakes sometimes.

Try adding a Start-Wait at the beginning of post installation. Perhaps the 365 CTR shortcuts are taking a while to generate? CTR is funky.

Thanks for the reply! I am testing it in a VM that has our image on it on my machine. I am launching through software center to test for now.

I am on my phone right now but I cant seem to find the missing bracket in the code abov. Can you let me know where you noticed it? I must be over looking it and I want to double check it when I am back at my PC.

The Start-Wait is a good idea and I will definitely give that a shot.

I added a Start-Sleep -s 15 after the office install and tried again but no luck. Same results.

The PSADT log shows everything running and finishing without error including the before and after install scheduled tasks created by Execute-ProcessAsUser.

In earlier iterations of these attempts I tried to set a runonce registry key for the currently logged on user to run this script and could not get that to work either.

I am truly at a loss as to why the second script is not working via SCCM when it works just fine when
run manually.