Hey guys,
Before posting I did to see if someone has faced similar issues but could not find the same use case so hopefully someone in this forum has any ideas that may be able to help me.
I am trying to create an Intune App package with the goal to
Installation:
a) Install application with list of arguments
Post Installation:
b) Add LoggedOnUser which is an “AzureAD” account to a Local Group. Please note, it’s not a Restricted Group like Administrators but instead a custom Local group created for the application we are trying to deploy to all endpoints.
Uninstallation:
c) Uninstall application
Post Uninstallation:
d) Remove folders from User Profiles (clean up post uninstallation being completed)
e) Remove LoggedOnUser from the Local Group
Please note, if I try to run this on my device with an elevated PS session, works fine but I have to be missing something as when I deploy the package to Intune, I can achieve the software installation, which sets the deployment as “Installed” but I can’t get the post installation working, see below what I have in the ps1
#Return SID
$key1 = [Microsoft.Win32.RegistryKey]::OpenBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, [Microsoft.Win32.RegistryView]::Registry64)
$subKey1 = $key1.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI")
$SID = $subKey1.GetValue("LastLoggedOnUserSID")
#Return UPN
$key2 = [Microsoft.Win32.RegistryKey]::OpenBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, [Microsoft.Win32.RegistryView]::Registry64)
$subKey2 = $key2.OpenSubKey("SOFTWARE\Microsoft\IdentityStore\Cache\$SID\IdentityCache\$SID")
$UPN = $subKey2.GetValue("UserName")
#Add Logged on user to Local Group
Add-LocalGroupMember -Group "MyApp Administrators" -Member "AzureAD\$UPN"
See below error from “C:\Windows\Logs\Software”
<![LOG[[Post-Installation] :: Error Record:
-------------
Message : The term 'Add-LocalGroupMember' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
InnerException :
FullyQualifiedErrorId : CommandNotFoundException
ScriptStackTrace : at <ScriptBlock>,
C:\windows\IMECache\59884cac-bfa0-49f2-9079-ae7911217ea5_1\Deploy-Application.ps1: line 212
at <ScriptBlock>, <No file>: line 1
PositionMessage : At C:\windows\IMECache\59884cac-bfa0-49f2-9079-ae7911217ea5_1\Deploy-Application.ps1:212 char:3
+ Add-LocalGroupMember -Group "MyApp Administrators" -Member ...
+ ~~~~~~~~~~~~~~~~~~~~
]LOG]!><time="15:35:34.294600" date="09-08-2023" component="Deploy Application" context="NT AUTHORITY\SYSTEM" type="3" thread="13904" file="Deploy-Application.ps1">
<![LOG[[Post-Installation] :: Bypassing Show-DialogBox [Mode: NonInteractive]. Text:Error Record:
-------------
Message : The term 'Add-LocalGroupMember' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
InnerException :
FullyQualifiedErrorId : CommandNotFoundException
ScriptStackTrace : at <ScriptBlock>,
C:\windows\IMECache\59884cac-bfa0-49f2-9079-ae7911217ea5_1\Deploy-Application.ps1: line 212
at <ScriptBlock>, <No file>: line 1
PositionMessage : At C:\windows\IMECache\59884cac-bfa0-49f2-9079-ae7911217ea5_1\Deploy-Application.ps1:212 char:3
+ Add-LocalGroupMember -Group "MyApp Administrators" -Member ...
+ ~~~~~~~~~~~~~~~~~~~~
I have also try putting this in a ps script but Intune ignores it as well
Help!