question

RiteshSharma-3070 avatar image
0 Votes"
RiteshSharma-3070 asked RiteshSharma-3070 commented

Powershell script to get laptop hash value remotely using Endpoint manager

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-powershellmem-intune-admin-center
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

For what reason is it failing?

0 Votes 0 ·
LimitlessTechnology-2700 avatar image
0 Votes"
LimitlessTechnology-2700 answered RiteshSharma-3070 commented

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://docs.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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Limitless, thank you for your reply. I will get the error logs and share you soon. I will try your recommendation too.

0 Votes 0 ·

Hi Limitless, after installing NuGet package provider. The script is working fine now. Thank you for your response here.

0 Votes 0 ·
Crystal-MSFT avatar image
0 Votes"
Crystal-MSFT answered Crystal-MSFT commented

@RiteshSharma-3070, 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://docs.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.


· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you, Crystal for your reply! is there any way i can add the command to run using share permission account credentials?

The link you shared to import the device hash value. Its require device access and I want to looking for something can be run remotely using Endpoint manager.

0 Votes 0 ·
Crystal-MSFT avatar image Crystal-MSFT RiteshSharma-3070 ·

@RiteshSharma-3070, Thanks for the reply. After running the script on my device, I find "Set-Location -Path" is not correct. .
197584-image.png

Here are the script I run successfully before for the reference:

md c:\HWID
Set-Location c:\HWID
Set-ExecutionPolicy Unrestricted
Install-Script -Name Get-WindowsAutopilotInfo
Get-WindowsAutopilotInfo.ps1 -OutputFile AutopilotHWID.csv


0 Votes 0 ·
image.png (134.6 KiB)

Hi Crystal, thank you for your reply, Set-Location -path is just a parameter. We need to add argument here. Which i didn't mentioned. As, its our internal Egnyte drive path. However, commands shared above are working fine manually and giving me the result.

0 Votes 0 ·
Show more comments
RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered RichMatheisen-8856 commented

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.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Rich, thank you for your reply, Set-Location -path is just a parameter. We need to add argument here. Which i didn't mentioned. As, its our internal Egnyte drive path. However, commands shared above are working fine manually and giving me the result.

0 Votes 0 ·

It probably works when you run it in a PowerShell session because the current directory allows you to create a file named "X<space>AutoPilotHWID.csv".

In which directory will that file be written when it's run by your automation? And as which user account is the script run by your automation?

So far you've only said "it doesn't work" but haven't provided any details about why it fails.

0 Votes 0 ·