Share via

Run a PowerShell Script in Intune to run a PowerShell save in Azure Blob

Sam Na 46 Reputation points
2021-01-31T21:01:22.563+00:00

Hi,

Trying to upload a PowerShell script to Intune to be pushed to all endpoint devices to copy a file that is stored in my Azure blob storage to the desktop of all users.

What is the right format\commnad to perform this task?


Script and results:

$BlobUri = 'https://xxxxxxx.file.core.windows.net/intune/Volume Licensing Service Center.url'
$Sas = '?sp=rl&st=2021-01-31T04:52:54Z&se=2021-02-01T04:52:54Z&sv=2019-12-12&sig=Gqv%2FhEspZsoR74gwMpXbeCWWnxoQBFwNIjCaJ4%2FXY%2BU%3D&sr=f'

Output Path with \ on the end

$OutputPath = 'C:\Users\' + $env:UserName + '\Desktop\'

Gets full Uri

$FullUri = "$BlobUri$Sas"

Downloads file to outpath with correct file type and file found in BlobURI

(New-Object System.Net.WebClient).DownloadFile($FullUri, $OutputPath + ($BlobUri -split '/')[-1])
Exception calling "DownloadFile" with "2" argument(s): "An exception occurred during a WebClient request."
At line:14 char:1

  • (New-Object System.Net.WebClient).DownloadFile($FullUri, $OutputPath ...
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • CategoryInfo : NotSpecified: (:) [], MethodInvocationException
  • FullyQualifiedErrorId : WebException
Azure Blob Storage
Azure Blob Storage

An Azure service that stores unstructured data in the cloud as blobs.

Windows for business | Windows Server | User experience | PowerShell
Microsoft Security | Intune | Configuration
0 comments No comments

2 answers

Sort by: Most helpful
  1. Crystal-MSFT 54,306 Reputation points Microsoft External Staff
    2021-02-01T02:39:26.517+00:00

    @Sam Na , This is from Intune support, from your description, I know you want to write a Powershell Script to copy a file in Azure Blob storage to the endpoint device.

    Based on my understanding, If the endpoint devices are with Windows 10 OS, to accomplish this, we can refer to the following 3 steps to make it work:

    1. Make sure the Powershell commands can work well on one endpoint device.
    2. Combine all the commands together and write a Powershell script. Test on one endpoint device to make sure the script is working well.
    3. Consider to deploy the script via Intune.
      https://learn.microsoft.com/en-us/mem/intune/apps/intune-management-extension

    From the information you provided, I find there's error during downloading file from Azure Blob storage. Here, we will add a "Azure-blob-storage" tag for you to see if a related engineer can be involved to help on this. If not, we suggest to submit a new thread to the following location and only with "Azure-blob-storage" tag to get the related support.
    https://learn.microsoft.com/en-us/answers/topics/azure-blob-storage.html

    Please firstly fix the above issue and if there's any Intune deployment issue, feel free to let me know.


    If the response is helpful, please click "Accept Answer" and upvote it.
    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. NickH 3,526 Reputation points Volunteer Moderator
    2021-01-31T22:59:26.027+00:00

    Why don't you just package up the script and content as a Win32 app and then deploy it? You can run the script as the installation command line. As an example https://oliverkieselbach.com/2018/12/15/deploying-win32-app-bginfo-with-intune/

    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.