Set a Registry Key Value for Current User - Help Needed

Is it possible for the toolkit to set a registry value for the logged on user? I know it runs as system but I’m sure there’s a way, I just can’t figure it out…

I tried:

Set-RegistryKey -Key 'HKCU\Software\IM Providers' -Name 'DefaultIMApp' -Value 'Teams' -Type String -SID $UserProfile.SID

But got:

[Installation] :: Error Record:
-------------

Message        : Cannot validate argument on parameter 'SID'. The argument is null or empty. Provide an argument that 
                 is not null or empty, and then try the command again.
InnerException : System.Management.Automation.ValidationMetadataException: The argument is null or empty. Provide an 
                 argument that is not null or empty, and then try the command again.
                    at System.Management.Automation.ValidateNotNullOrEmptyAttribute.Validate(Object arguments, 
                 EngineIntrinsics engineIntrinsics)
                    at System.Management.Automation.ParameterBinderBase.BindParameter(CommandParameterInternal 
                 parameter, CompiledCommandParameter parameterMetadata, ParameterBindingFlags flags)

FullyQualifiedErrorId : ParameterArgumentValidationError,Set-RegistryKey
ScriptStackTrace      : at <ScriptBlock>, C:\WINDOWS\ccmcache\26\Deploy-Application.ps1: line 145
                        at <ScriptBlock>, <No file>: line 1
                        at <ScriptBlock>, <No file>: line 1

PositionMessage : At C:\WINDOWS\ccmcache\26\Deploy-Application.ps1:145 char:107
                  + ... Name 'DefaultIMApp' -Value 'Teams' -Type String -SID $UserProfile.SID
                  +                                                          ~~~~~~~~~~~~~~~~



Error Inner Exception(s):
-------------------------

Message        : The argument is null or empty. Provide an argument that is not null or empty, and then try the 
                 command again.
InnerException :

Any help is appreciated. Thanks!

$LoggedOnuser = Get-LoggedOnUser

If ($LoggedOnuser.IsConsoleSession){
Set-RegistryKey -Key ‘HKCU\Software\IM Providers’ -Name ‘DefaultIMApp’ -Value ‘Teams’ -Type String -SID $LoggedOnuser.SID }

Thanks for the reply… Just got around to testing…

Here is what I have in my “”

$LoggedOnuser = Get-LoggedOnUser
If ($LoggedOnuser.IsConsoleSession){
Set-RegistryKey -Key ‘HKCU\Software\IM Providers’ -Name ‘DefaultIMApp’ -Value ‘Teams’ -Type String -SID $LoggedOnuser.SID }

I ran it but don’t see any errors or even the registry command running in the log… What am I doing wrong here?

Thanks

<![LOG[[Initialization] :: *******************************************************************************]LOG]!><time="11:07:11.398-240" date="05-21-2020" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: *******************************************************************************]LOG]!><time="11:07:11.398-240" date="05-21-2020" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: [VENDERNAMEHERE_APPNAMEHERE_EN_01] setup started.]LOG]!><time="11:07:11.569-240" date="05-21-2020" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Script [C:\WINDOWS\ccmcache\2e\AppDeployToolkit\AppDeployToolkitMain.ps1] dot-source invoked by [C:\WINDOWS\ccmcache\2e\Deploy-Application.ps1]]LOG]!><time="11:07:11.585-240" date="05-21-2020" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Script [C:\WINDOWS\ccmcache\2e\AppDeployToolkit\AppDeployToolkitExtensions.ps1] dot-source invoked by [C:\WINDOWS\ccmcache\2e\AppDeployToolkit\AppDeployToolkitMain.ps1]]LOG]!><time="11:07:11.592-240" date="05-21-2020" component="PSAppDeployToolkitExt" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitExtensions.ps1">
<![LOG[[Initialization] :: [VENDERNAMEHERE_APPNAMEHERE_EN_01] script version is [1.0.0]]LOG]!><time="11:07:11.636-240" date="05-21-2020" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: [Deploy Application] script version is [3.7.0]]LOG]!><time="11:07:11.640-240" date="05-21-2020" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: The following non-default parameters were passed to [Deploy Application]: [-DeployMode "Silent"]]LOG]!><time="11:07:11.644-240" date="05-21-2020" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: [App Deploy Toolkit Main] script version is [3.7.0]]LOG]!><time="11:07:11.648-240" date="05-21-2020" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: [App Deploy Toolkit Extensions] version is [1.5.0]]LOG]!><time="11:07:11.653-240" date="05-21-2020" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Computer Name is [COMPUTER.DOMAIN.COM]]LOG]!><time="11:07:11.657-240" date="05-21-2020" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Current User is [NT AUTHORITY\SYSTEM]]LOG]!><time="11:07:11.661-240" date="05-21-2020" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: OS Version is [Microsoft Windows 10 Enterprise 64-bit 10.0.17134.1488]]LOG]!><time="11:07:11.666-240" date="05-21-2020" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: OS Type is [Workstation]]LOG]!><time="11:07:11.670-240" date="05-21-2020" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Current Culture is [en-US], language is [EN] and UI language is [EN]]LOG]!><time="11:07:11.676-240" date="05-21-2020" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Hardware Platform is [Physical]]LOG]!><time="11:07:11.792-240" date="05-21-2020" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: PowerShell Host is [ConsoleHost] with version [5.1.17134.858]]LOG]!><time="11:07:11.800-240" date="05-21-2020" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: PowerShell Version is [5.1.17134.858 x64]]LOG]!><time="11:07:11.804-240" date="05-21-2020" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: PowerShell CLR (.NET) version is [4.0.30319.42000]]LOG]!><time="11:07:11.808-240" date="05-21-2020" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: *******************************************************************************]LOG]!><time="11:07:11.813-240" date="05-21-2020" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Display session information for all logged on users: 


NTAccount           : DOMAIN\USER
SID                 : SID
UserName            : USER
DomainName          : DOMAIN
SessionId           : 2
SessionName         : RDP-Tcp#5
ConnectState        : Active
IsCurrentSession    : True
IsConsoleSession    : False
IsActiveUserSession : True
IsUserSession       : True
IsRdpSession        : True
IsLocalAdmin        : False
LogonTime           : 5/19/2020 3:17:40 PM
IdleTime            : 00:00:01.0627701
DisconnectTime      : 5/21/2020 10:46:18 AM
ClientName          : COMPUTER
ClientProtocolType  : RDP
ClientDirectory     : C:\WINDOWS\system32\mstscax.dll
ClientBuildNumber   : 17134



]LOG]!><time="11:07:12.215-240" date="05-21-2020" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: The following users are logged on to the system: [DOMAIN\USER].]LOG]!><time="11:07:12.219-240" date="05-21-2020" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Current process is running with user account [NT AUTHORITY\SYSTEM] under logged in user session for [DOMAIN\USER].]LOG]!><time="11:07:12.224-240" date="05-21-2020" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: There is no console user logged in (user with control of physical monitor, keyboard, and mouse).]LOG]!><time="11:07:12.229-240" date="05-21-2020" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: The active logged on user is [DOMAIN\USER].]LOG]!><time="11:07:12.233-240" date="05-21-2020" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: The active logged on user [DOMAIN\USER] has a primary UI language of [EN].]LOG]!><time="11:07:12.236-240" date="05-21-2020" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: The following UI messages were imported from the config XML file: [UI_Messages_EN].]LOG]!><time="11:07:12.241-240" date="05-21-2020" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: The active logged on user [DOMAIN\USER] has a DPI scale factor of [100] with DPI pixels [96].]LOG]!><time="11:07:12.245-240" date="05-21-2020" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Unable to load COM Object [Microsoft.SMS.TSEnvironment]. Therefore, script is not currently running from a SCCM Task Sequence.]LOG]!><time="11:07:12.361-240" date="05-21-2020" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Service [EventSystem] exists.]LOG]!><time="11:07:12.726-240" date="05-21-2020" component="Test-ServiceExists" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Get the service [EventSystem] startup mode.]LOG]!><time="11:07:12.742-240" date="05-21-2020" component="Get-ServiceStartMode" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Service [EventSystem] startup mode is set to [Automatic].]LOG]!><time="11:07:12.965-240" date="05-21-2020" component="Get-ServiceStartMode" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Get the service object for service [EventSystem].]LOG]!><time="11:07:13.019-240" date="05-21-2020" component="Start-ServiceAndDependencies" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Service [EventSystem] with display name [COM+ Event System] has a status of [Running].]LOG]!><time="11:07:13.056-240" date="05-21-2020" component="Start-ServiceAndDependencies" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Service [RpcSs] exists.]LOG]!><time="11:07:13.277-240" date="05-21-2020" component="Test-ServiceExists" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Get the service [RpcSs] startup mode.]LOG]!><time="11:07:13.287-240" date="05-21-2020" component="Get-ServiceStartMode" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Service [RpcSs] startup mode is set to [Automatic].]LOG]!><time="11:07:13.468-240" date="05-21-2020" component="Get-ServiceStartMode" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Get the service object for service [RpcSs].]LOG]!><time="11:07:13.477-240" date="05-21-2020" component="Start-ServiceAndDependencies" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Service [RpcSs] with display name [Remote Procedure Call (RPC)] has a status of [Running].]LOG]!><time="11:07:13.481-240" date="05-21-2020" component="Start-ServiceAndDependencies" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Service [EventLog] exists.]LOG]!><time="11:07:13.703-240" date="05-21-2020" component="Test-ServiceExists" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Get the service [EventLog] startup mode.]LOG]!><time="11:07:13.712-240" date="05-21-2020" component="Get-ServiceStartMode" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Service [EventLog] startup mode is set to [Automatic].]LOG]!><time="11:07:13.901-240" date="05-21-2020" component="Get-ServiceStartMode" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Get the service object for service [EventLog].]LOG]!><time="11:07:13.910-240" date="05-21-2020" component="Start-ServiceAndDependencies" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Service [EventLog] with display name [Windows Event Log] has a status of [Running].]LOG]!><time="11:07:13.915-240" date="05-21-2020" component="Start-ServiceAndDependencies" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Service [Schedule] exists.]LOG]!><time="11:07:14.136-240" date="05-21-2020" component="Test-ServiceExists" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Get the service [Schedule] startup mode.]LOG]!><time="11:07:14.163-240" date="05-21-2020" component="Get-ServiceStartMode" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Service [Schedule] startup mode is set to [Automatic].]LOG]!><time="11:07:14.341-240" date="05-21-2020" component="Get-ServiceStartMode" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Get the service object for service [Schedule].]LOG]!><time="11:07:14.350-240" date="05-21-2020" component="Start-ServiceAndDependencies" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Service [Schedule] with display name [Task Scheduler] has a status of [Running].]LOG]!><time="11:07:14.355-240" date="05-21-2020" component="Start-ServiceAndDependencies" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: The task scheduler service is in a healthy state: True.]LOG]!><time="11:07:14.362-240" date="05-21-2020" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Session 0 detected, process running in user interactive mode, user(s) logged in.]LOG]!><time="11:07:14.366-240" date="05-21-2020" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Installation is running in [Silent] mode.]LOG]!><time="11:07:14.370-240" date="05-21-2020" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Deployment type is [Installation].]LOG]!><time="11:07:14.374-240" date="05-21-2020" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="AppDeployToolkitMain.ps1">
<![LOG[[Installation] :: Get session information for all logged on users.]LOG]!><time="11:07:14.395-240" date="05-21-2020" component="Get-LoggedOnUser" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="Deploy-Application.ps1">
<![LOG[[Post-Installation] :: VENDERNAMEHERE_APPNAMEHERE_EN_01 Installation completed with exit code [0].]LOG]!><time="11:07:14.459-240" date="05-21-2020" component="Exit-Script" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="Deploy-Application.ps1">
<![LOG[[Post-Installation] :: -------------------------------------------------------------------------------]LOG]!><time="11:07:14.463-240" date="05-21-2020" component="Exit-Script" context="NT AUTHORITY\SYSTEM" type="1" thread="1520" file="Deploy-Application.ps1">

Actually it did work! Just the copy / paste from the site screwed up the '.

Thanks!