I need to invoke an async method of a CLR type like this:
$tokenTask = $tokenProvider.AcquireAccessToken()
$tokenTask.Wait()
Write-Output "Token: $($tokenTask.Result)"
This in not working since it for some reason cannot successfully invoke Wait:
Exception calling "Wait" with "0" argument(s): "One or more errors occurred."
At D:\UserManagement\STP.UserManagement.Identity.Client\STP.UserManagement.Identity.Client.Sample\authenticate.ps1:8 char:1
+ $tokenTask.Wait()
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : AggregateException
How can I wait and get the result of my async method?
Is there a keyword like await in PowerShell?