Executing a PowerShell with admin privilege via Intune.

Sheik Mohamed Yasar 165 Reputation points
2023-12-13T14:49:08.99+00:00

Hi

I'm trying to uninstall an application from the client machine via Intune. To do that I have deployed a PowerShell script through the Intune portal. However the script failed to run despite configured to run "System Context". Please help.

Microsoft Intune
Microsoft Intune
A Microsoft cloud-based management solution that offers mobile device management, mobile application management, and PC management capabilities.
5,570 questions
{count} votes

2 answers

Sort by: Most helpful
  1. ZhoumingDuan-MSFT 16,755 Reputation points Microsoft External Staff
    2023-12-14T05:54:06.44+00:00

    @Sheik Mohamed Yasar,Thanks for posting in Q&A.

    From your description, I know that you want to uninstall an application via Intune, but the script failed to run.

    To clarify this issue, here are some information you can check.

    1.Please check whether the script can run on targeted device with admin.

    (1.Download PSTools and run CMD as admin.    [https://learn.microsoft.com/en-us/sysinternals/downloads/psexec](https://learn.microsoft.com/en-us/sysinternals/downloads/psexec)
    
    (2.CD to PSTools directory.
    
    (3.Enter psexec -i -d -s cmd.exe tp run cmd in system context.
    
    (4.Enter whoami to check running context.
    
    (5.Enter the uninstall command to test if it can work.
    

    2.Please check if exists related errors in IME and AgentExecutor log. Location: C:\ProgramData\Microsoft\IntuneManagementExtension\Logs.

    Please try above information, if there is any update, feel free to let me know.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Pavel yannara Mirochnitchenko 12,841 Reputation points MVP
    2023-12-14T18:45:24.43+00:00

    Depending on the app, you could create Win32 app (if you haven't done that already) for this app and try to uninstall the app by using a)msiexec /x {productcode} /qn -string or b)finding possible uninstall.exe type of file inside Program Files of that app. You then specify on of options to Win32 app uninstall string and deploy the app's uninstall deployment to device or users. Win32 app does support User and Device context approach. With only using powershell script in user context, you will be missing admin previleges for uninstallation, but Win32 should cover that.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.