I have been creating a powershell script to display toast notifications, this code works but there is one method on the toastnotification object I dont understand how to use:
$Load = [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]
$Load = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($App).Show($ToastXml)
Looking at the [Windows.UI.Notifications.ToastNotificationManager] object there is one method named "GetForUser()" https://learn.microsoft.com/en-us/uwp/api/windows.ui.notifications.toastnotificationmanager.getforuser?view=winrt-19041
This method needs a Windows.System.User object as input. https://learn.microsoft.com/en-us/uwp/api/windows.system.user?view=winrt-19041
I have tried the following code
$Load = [Windows.System.User, Windows.System, ContentType = WindowsRuntime]
$users = [Windows.System.User]::FindAllAsync()
$users is then a "System.__ComObject" without any methods.
So the question is, how can i get a Windows.System.User in PowerShell that I can use with the GetForUser() method of Windows.UI.Notifications.ToastNotificationManager?
I have also tried managed code
$code = @"
using Windows.System;
namespace CUser
{
public static class GetUsers{
public static void Main(){
IReadOnlyList<User> users = await User.FindAllAsync(UserType.LocalUser, UserAuthenticationStatus.LocallyAuthenticated);
User user = users.FirstOrDefault();
}
}
}
"@
Add-Type -TypeDefinition $code -Language CSharp
But that gives the error: "The type or namespace name 'System' does not exist in the namespace 'Windows' (are you missing an assembly reference?)"
I am not sure what assembly or dll contains the "Windows.System" reference.
I was searching for a similar problem with
DeviceInformation
and ran across your question. The solution turned out to be in this blog post https://fleexlab.blogspot.com/2018/02/using-winrts-iasyncoperation-in.htmlYou can then run
FindAllAsync()
like this