Powershell script to get laptop hash value remotely using Endpoint manager

Ritesh Sharma 81 Reputation points
2022-04-27T14:44:32.09+00:00

Hi Team, I am looking for a PowerShell script to extract system hash value from device and save into network path. I have below commands and manually it is running fine and giving me the result too. But, if I run this command using Powershell script from Intune. It is getting failed. Any suggestion will be appreciated.

Set-Location -Path
$env:Path += ";C:\Program Files\WindowsPowerShell\Scripts"
Set-ExecutionPolicy -Scope Process -ExecutionPolicy RemoteSigned -Force
Install-Script -Name Get-WindowsAutoPilotInfo
Get-WindowsAutoPilotInfo -OutputFile "$env:computername AutoPilotHWID.csv"

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,452 questions
{count} votes

Accepted answer
  1. Limitless Technology 39,506 Reputation points
    2022-04-29T08:50:13.427+00:00

    Hello RiteshSharma,

    It would be very helpful if you could explain how it fails or add text or screenshot of the returned error.

    In the meantime, I can recommend to add installation for NuGet packageprovider, as it will be required to run Get-WindowsAutoPilotInfo

    You can see the syntax here: https://learn.microsoft.com/en-us/powershell/module/packagemanagement/install-packageprovider?view=powershell-7.2#example-2-install-a-specified-version-of-a-package-provider

    ----------------------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept as answer--


2 additional answers

Sort by: Most helpful
  1. Crystal-MSFT 45,986 Reputation points Microsoft Vendor
    2022-04-28T01:49:47.56+00:00

    @Ritesh Sharma , Thanks for the reply. For our issue,Based as I know, it is related to permission. In the official article, it shows that running this script needs elevated permission.
    https://learn.microsoft.com/en-us/mem/autopilot/add-devices#powershell

    So in Intune, when we deploy the script, we need to choose the "Run the script using the logged on credentials" as no which means the script is run with system context.

    But I notice in the script you choose to save the csv to network path. This require the account running the script needs share permission on the network path. The system account on other device can't be assigned the share permission. So I think this is the reason for our issue.

    If you want finally import the device hash into Intune, here is a good link for your reference:
    https://oofhours.com/2020/03/25/importing-a-device-hash-directly-into-intune/
    Note: Non-Microsoft link, just for the reference.

    Hope it 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. Rich Matheisen 45,671 Reputation points
    2022-04-28T18:06:15.88+00:00

    In the code you posted, is the value of the "-OutputFile" parameter correct?

    Get-WindowsAutoPilotInfo -OutputFile "$env:computername AutoPilotHWID.csv"
    

    If that were run on a machine named "X" the file path would be X<space>AutoPilotHWID.csv and it would be written to the current directory.

    I see a Set-Location -Path at the beginning of that code, too . . . but it's missing the argument that should follow the -Path parameter.