Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Has PowerShell 7.2.12 broken Connect-MgGraph with AccessToken?

Since upgrading our build agents from PowerShell 7.2.11 to 7.2.12, they have been reporting the following error:

Cannot bind parameter 'AccessToken'. Cannot convert the *** value of type "System.String" to type "System.Security.SecureString".

Our script is as follows:

param(
    [Parameter(Mandatory)]
    [string]$graphApiToken
)

Connect-MgGraph -AccessToken $graphApiToken

This was working previously, and rolling back to our previous build agent image has resolved the issue.

like image 543
Mike Avatar asked Jan 21 '26 10:01

Mike


1 Answers

As mentioned in the comments, this is a change in behavior between v1.0 and v2.0 of the Microsoft Graph PowerShell module.

If you want your scripts to maintain compatibility with v1.0, simply convert the access token value conditionally:

param(
    [Parameter(Mandatory)]
    [string]$graphApiToken
)

$targetParameter = (Get-Command Connect-MgGraph).Parameters['AccessToken']

if ($targetParameter.ParameterType -eq [securestring]){
  Connect-MgGraph -AccessToken ($graphApiToken |ConvertTo-SecureString -AsPlainText -Force)
}
else {
  Connect-MgGraph -AccessToken $graphApiToken
}
like image 136
Mathias R. Jessen Avatar answered Jan 25 '26 09:01

Mathias R. Jessen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!