Intune does not deploy powershell script

Luis Sebastiao 0 Reputation points

My company acquired a smaller company with about 70 laptops. We are trying to get the Hardware Hash of all those laptops in an automated way so we can reimage the laptops with your Intune using autopilot. For that, I build a PowerShell script that I am trying to deploy as a Win32 app on that company. This script will get the hardware hash and upload it to an Azure Blob.

The script works perfectly if I run it locally with admin rights on the machine. The detection method, I am using manual detection with a file that the scripts create called hashidconfirm.txt. The command that I am using is powershell.exe -ExecutionPolicy Bypass -File .\hashid.ps1 in the install field in the Win32 configuration.

However, the script does not work when deployed this way, and I can not figure out why. Am I doing something wrong?

#Define variables

Install-Module -Name Az.Storage -force

Install-Script -Name Get-WindowsAutoPilotInfo -force

$StorageAccountName = "XXXXX"

$StorageAccountKey = "XXXXXX"

$ContainerName = "XXXXX"

$Serial = (Get-CimInstance win32_bios).SerialNumber

$Context = New-AzStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey

New-Item -ItemType Directory -Path C:\Intune\

#Create the local file

Get-WindowsAutoPilotInfo -Outputfile C:\Intune\$Serial.csv

#Upload the file to Azure blob storage

Set-AzStorageBlobContent -Context $Context -Container $ContainerName -File "C:\Intune\$Serial.csv"

#Delete the local file

Remove-Item -Path "C:\Intune\$Serial.csv"

New-Item -Path "C:\Intune\hashidconfirm.txt"

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
9,480 questions
Microsoft Intune
Microsoft Intune
A Microsoft cloud-based management solution that offers mobile device management, mobile application management, and PC management capabilities.
3,680 questions
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
1,550 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Felipe Santos Cardoso 1 Reputation point

    Hello Luis Sebastiao

    I would like to contribute to the "Online" registration method (get-windowsautopilotinfo.ps1 -online).

    Andrew's post may help you with Graph and Enterprise Application permissions:


    #Define variables

    Install-Module -Name Az.Storage -force

    Install-Script -Name Get-WindowsAutoPilotInfo -force

    get-windowsautopilotinfo.ps1 -online -TenantID 12345 -appid 12345 -appsecret 12345

    0 comments No comments

  2. ZhoumingDuan-MSFT 2,440 Reputation points Microsoft Vendor

    @Luis Sebastiao, Thanks for posting in Q&A.

    From your description, I know that you have built a PowerShell script to get Hardware Hash of all laptops but get some errors.

    To clarify this issue, please provide us with some information.

    • Provide us the win32 app configurations in Intune

    • Go to the targeted device and check if there is related error message in IME, AgentExecutor log. Location C:\ProgramData\Microsoft\IntuneManagementExtension\Logs.

    Thanks for your kind understanding.

    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.

  3. Nick Eckermann 346 Reputation points

    Make sure you don't have anything blocking powershell from working correctly such as signing requirements and things like that.

    Make sure for your script is in the root of the source directory you use to package the application.

    Use this for the install command for the application.

    powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -NoProfile -File NameOfScript.ps1

    0 comments No comments