Forum Discussion
Mandatory AccessKey parameter for Import-WACConnection Powershell cmdlet in 2410
I had a good look through the PowerShell Connection Tools Module - Microsoft.WindowsAdminCenter.ConnectionTools.psm1 found in C:\Program Files\WindowsAdminCenter\PowerShellModules\Microsoft.WindowsAdminCenter.ConnectionTools and found multiple errors:
- Some very basic inconsistencies in variable names
- Logical errors in the order of some lines
- Mistakes in the names of functions being called
- Missing parameters being passed to functions
- Responses not being returned from some functions
The sum of all of this is the script barely worked at all!
I have made necessary corrections and also set the AccessKey parameter to not mandatory. My version of the script now works to import and delete connections for those using Kerberos.
I am staggered that this script has been put in to production by Microsoft. It really is quite appalling how broken it is and how easy it would have been to check and fix the script by the developers!
That sounds great, can you share your modified script ?
- andyroonzMay 29, 2025Brass Contributor
I am not sure if it is okay to share the corrected code here? It is Microsoft licensed code.
But here are the errors I found:
- The variable $credentials is called $credential incorrectly in a few places
- The RemoveConnection function is never called by the Import-WACConnection because when they are trying to call that function they are using Remove-Connection. Just need to remove the hyphen here.
- When they call the RemoveConnection function they are also using a variable that has never had its value set: $GatewayEndpoint (as well as $credential mentioned earlier). This should be $Endpoint. They also haven't named the parameters on this line and the variables are in the wrong order. Easiest to name the variables e.g. -Endpoint -ConnectionId -Credential.
- Line 46 is where they use a code block to check for the $accessToken. Use this format for the RemoveConnection and ApplyConnection functions as well. Remove line 120.
- You will also need to return the response from the RemoveConnection and ApplyConnection functions with "return $response" at the end of these functions
- Set the $AccessKey parameter Mandatory = $false if you use Kerberos in the Import-WACConnection function
I think that covers most of it.