Share via

Attach powershell script to Intune package

Thomas Reddy 0 Reputation points
2023-05-24T19:58:06.46+00:00

Hi,

I'm trying to run a PowerShell script to copy some .xml files from network location to client machines (C:\ProgramData\PCDr\etc). When I run the script on the client as an admin it works and copies the files to the location but when Intune runs it as system context (Device-Scripts) it fails and I see permission, to the destination folder, error. To my best knowledge Intune is pushing the script through with admin rights. I must be missing something and any assistance with this will be appreciated.

Thank you

Windows for business | Windows Client for IT Pros | Devices and deployment | Configure application groups
Windows for business | Windows Server | User experience | PowerShell
Microsoft Security | Intune | Application management
0 comments No comments

1 answer

Sort by: Most helpful
  1. Lu Dai-MSFT 28,531 Reputation points
    2023-05-25T02:19:03.5633333+00:00

    @Thomas Reddy Thanks for posting in our Q&A.

    For this issue, running the script on the client as an admin successfully doesn't mean that it will work when you deploy the script via intune.

    It is suggested to try to run the script in the System account using the psexec tool. If it works well, we can deploy the script via intune. Here are the steps:

    1.Install PsExec

    https://learn.microsoft.com/en-us/sysinternals/downloads/psexec

    2.Copy PsExec.exe to C:\Windows\System32

    3.Open Powershell as admin and run the following command:

    PsExec.exe -s -i powershell.exe
    
    

    4.Then run the script in the new PowerShell windows.

    If there is anything update, feel free to let us know.


    If the answer is the right solution, 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.

    Was this answer helpful?


Your answer

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