Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-AutopilotDevice() - the issue with space(s) in the serial number #1

Closed
najki78 opened this issue Jun 9, 2023 · 3 comments
Closed

Comments

@najki78
Copy link

najki78 commented Jun 9, 2023

Hello Andrew,
I have dealt with the same issue recently (it is on Microsoft side) and since the trick with '[uri]::EscapeDataString($serial)' does not work unfortunately, the solution was to do it in two parts:

# get all the devices with the same (up to a first space) serial number 
$SerialWithoutSpace = $serial.split(" ")
$uri = "https://graph.microsoft.com/$graphApiVersion/$($Resource)?`$filter=contains(serialNumber,'$($SerialWithoutSpace[0])')"

and then to filter the device with the exact serial number:

$devicesResponse.value | Where-Object {$_.serialNumber -eq "$($serial)"}
@andrew-s-taylor
Copy link
Owner

I've just updated to v3.7 which adds your fix. I've added some logic around it to it checks for spaces first.
Can you see if that works any better? I don't have any devices with spaces in the serials to test with
Thank you

@najki78
Copy link
Author

najki78 commented Jun 10, 2023

Hello Andrew,
wow, that was super fast! Thank you.
I have just tested (my lab VMware virtual machines have spaces in the names) and I would suggest one small change:
Instead of
$devices = $response.value
to replace by

if ($serialhasspaces -eq 1) {  
     $devices = $response.value | Where-Object {$_.serialNumber -eq "$($serial)"}
} else {
     $devices = $response.value 
}

@andrew-s-taylor
Copy link
Owner

Well spotted, added on 3.8

@najki78 najki78 closed this as completed Jun 12, 2023
andrew-s-taylor pushed a commit that referenced this issue Feb 5, 2024
AkosBakos added a commit to AkosBakos/WindowsAutopilotInfo that referenced this issue Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants