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 10 Security
Windows 10 Security
Windows 10: A Microsoft operating system that runs on personal computers and tablets.Security: The precautions taken to guard against crime, attack, sabotage, espionage, or another threat.
2,752 questions
Microsoft Intune Application management
Microsoft Intune Application management
Microsoft Intune: A Microsoft cloud-based management solution that offers mobile device management, mobile application management, and PC management capabilities.Application management: The process of creating, configuring, managing, and monitoring applications.
873 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,043 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Lu Dai-MSFT 28,341 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.