I'm attempting to run a PowerShell script that manages Wi-Fi profiles (specifically WPA3) through Intune. The script executes correctly when run directly on clients, but it fails when executed through Intune, generating errors. The logs indicate there are unexpected spaces in the registry key paths. The script runs in the system context and experiences the same issues in both 32-bit and 64-bit modes. Here's the script I'm working with:
```powershell
# Wifi Profile "Added by company policy"
$WifiProfileName = "Corporate Wi-Fi"
$Path = "C:\ProgramData\Microsoft\Wlansvc\Profiles\Interfaces"
$interfaces=Get-ChildItem $Path
foreach ($interface in $interfaces) {
$profiles = Get-ChildItem $interface.FullName
foreach ($profile in $profiles) {
$xml = get-content $profile.fullname
if ($xml -match $WifiProfileName) {
$profileguid = $($profile.name).Split('.')[0]
$reg = "HKLM:\SOFTWARE\Microsoft\WlanSvc\Interfaces\{$($interface.Name)}\Profiles\{$profileguid}\MetaData"
if ( (Get-Item $reg).property -contains "Connection Type" ) {
Write-Host "key exists"
} else {
New-ItemProperty -Path $reg -Name "Connection Type" -PropertyType Binary -Value ([byte[]](0x08,0x00,0x00,0x00))
}
}
}
}
```
I keep getting the following errors:
- `Get-Item : Cannot find path 'HKLM:SOFTWAREMicrosoftWlanSvcInterfaces{...}Profiles{...}MetaData' because it does not exist.`
Any suggestions would be greatly appreciated!
3 Answers
Remember that Intune executes scripts in a 32-bit context by default. You might need to ensure you're calling the correct version of PowerShell. Try running your script from the 64-bit path to see if it resolves the issue.
Have you thought about using the built-in configuration profile for adding a Wi-Fi profile instead of scripting? It could save you a lot of hassle, especially if the script runs fine on the client but not via Intune.
It might help if you use `Get-ItemProperty` or `Get-ItemPropertyValue` instead of `Get-Item`. These commands can directly query the properties you need without running into the path issues you're experiencing.

Good tip! I forgot about that. I’ll definitely try running it from the 64-bit path.