Why is my script failing to run via Intune for Wi-Fi profile management?

0
3
Asked By TechWiz42 On

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

Answered By PowerScriptMaster On

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.

ScriptKid -

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

Answered By CodeCrafty99 On

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.

Answered By DevGuru101 On

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.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.