Various technical articles, IT-related tutorials, software information, computer programming stuff. What else is there under the sun?

Friday, February 9, 2018

Using WinRT's IAsyncOperation in PowerShell

WinRT types can be used from PowerShell if explicitly named first. Many WinRT API methods are asynchronous, returning genericized IAsyncOperation objects that come into PowerShell as System.__ComObject. Trying to use any methods on such objects fails. Some people have written compiled assemblies in C# that convert async operations to standard .NET tasks and then await them, but this can be accomplished in pure PowerShell with some reflection: