Intune - Powershell

Sokoban 1,061 Reputation points
2024-02-27T20:25:35.82+00:00

Hi Im trying to copy with powershell script a screensaver file to C:\Windows\System32 The setup looks like that: Powershell

The powershell looks like that:

Get-ADComputer -Filter * -SearchBase "$Clients" | foreach{ if(-not(Test-Path "\\$($_.name)\c$\windows\system32\TheMatrix.scr")){ Copy-Item "\\XXXXXX\Software\ScreensaverMatrix\TheMatrix.scr" -Destination "\\$($_.name)\c$\windows\system32\" } }

I have got error , what is wrong and how i will troubleshooting that ? Sokoban

Windows for business | Windows Server | User experience | PowerShell
Microsoft Security | Intune | Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Crystal-MSFT 54,201 Reputation points Microsoft External Staff
    2024-02-28T01:59:55.56+00:00

    @Sokoban, Thanks for posting in Q&A. For PowerShell script deploy via Intune, we need to firstly test on the device side manually. From the script configuration, I find it runs using logged on credentials.

    Please manually run the script on one affected device with current user credential and see what error we get.

    However, if we can run the script successfully when test it manually, we can review IntuneManagementExtension.log to get more finding. Here are some links with some examples for your reference:

    https://oliverkieselbach.com/2018/02/12/part-2-deep-dive-microsoft-intune-management-extension-powershell-scripts/

    https://www.velessoftware.com/troubleshooting-intune-powershell-scripts/

    Note: Non-Microsoft link, just for the reference.

    Hope the above information can help.


    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. MotoX80 37,156 Reputation points
    2024-03-01T02:49:57.1433333+00:00

    My understanding of Intune is that it allows Admins to do things like run a script in the context of individual users on each machine in your organization. That's the "Included groups All Devices" and the "Run this script using the logged on credentials" part.

    Is it not?

    But your script is reading a list of computer names from active directory and looping though each of them, attempting to copy the file. So by using Intune you are having every user in your organization trying to copy the file to every client machine in your organization!!! (Edit: depending on how you populate the $clients variable.)

    You don't need Intune for that script, you just need to have an admin run it one time to distribute the file.

    If you want to use Intune, you just need to copy to the local C drive.

    And since you are copying the file to system32, the user will need to be a member of the administrators group on the PC otherwise you will get access denied. The Powershell process may also need to run elevated but I am not an Intune expert.

    if (-not(Test-Path "c:\windows\system32\TheMatrix.scr")) {
        "Copying file"
        Copy-Item "\\XXXXXX\Software\ScreensaverMatrix\TheMatrix.scr" -Destination "c:\windows\system32\" 
    } else {
        "File already exists"
    }
    
    
    0 comments No comments

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.