Skip to content

Instantly share code, notes, and snippets.

@ismits
Created July 2, 2019 15:12
Show Gist options
  • Save ismits/641abb9af87c2d93c3206c12ae582d77 to your computer and use it in GitHub Desktop.
Save ismits/641abb9af87c2d93c3206c12ae582d77 to your computer and use it in GitHub Desktop.
PowerShell function to wait for an async task to complete and return the result when completed
function Get-AsyncResult {
[CmdletBinding()]
[OutputType('Object')]
param (
[Parameter(Mandatory = $true, Position = 1)]
[object] $Task
)
Write-PSFMessage -Level Verbose -Message "Building the Task Waiter and start waiting." -Target $Task
$Task.GetAwaiter().GetResult()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment