Popup message

Hi All,

$Sender = “Bla Bla Bla”
$Message = “Bla Bla Bla.”
$RemoteComputer = “.”

Function New-ToastNotification {
Param($Sender,$Message,$Message1)

# Required parameters
$AudioSource = “ms-winsoundevent:Notification.Default”
$HeaderFormat = “ImageAndTitle” # Choose from “TitleOnly”, “ImageOnly” or “ImageAndTitle”
$Base64Image = “iVBORw0KGg…”

# Create an image file from base64 string and save to user temp location
If ($Base64Image)
{
$ImageFile = “$env:Temp\ToastLogo.png”
[byte[]]$Bytes = [convert]::FromBase64String($Base64Image)
[System.IO.File]::WriteAllBytes($ImageFile,$Bytes)
}

# Load some required namespaces
$null = [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]
$null = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]

# Register the AppID in the registry for use with the Action Center, if required
$app = ‘{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe’
$AppID = “{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe”
$RegPath = ‘HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings’

if (!(Test-Path -Path “$RegPath$AppId”)) {
$null = New-Item -Path “$RegPath$AppId” -Force
$null = New-ItemProperty -Path “$RegPath$AppId” -Name ‘ShowInActionCenter’ -Value 1 -PropertyType ‘DWORD’ -Force
}

# Define the toast notification in XML format
[xml]$ToastTemplate = @"
<toast duration=“long”>
<visual>
<binding template=“ToastGeneric”>
<text>$Sender</text>
<image placement=“appLogoOverride” hint-crop=“rectangle” src="$ImageFile"/>
<group>
<subgroup>
<text hint-style=“title” hint-wrap=“true” >$Message</text>
</subgroup>
</group>
</binding>
</visual>
<audio src="$AudioSource"/>
</toast>
"@

# Load the notification into the required format
$ToastXml = New-Object -TypeName Windows.Data.Xml.Dom.XmlDocument
$ToastXml.LoadXml($ToastTemplate.OuterXml)

# Display
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($app).Show($ToastXml)

}

#Invoke-Command -ComputerName $RemoteComputer -ScriptBlock ${function:New-ToastNotification} -ArgumentList $Sender,$Message

New-ToastNotification $Sender -Message $Message
}
else
{Write-Host “Not Need reboot”}

i run this script on end user machine:

powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -NonInteractive -NoProfile -File “.\test.ps1”

When i run this on user amchine I get : Access Denied

how i can run this script as current logged on user

Thanks.

brad, welcome back to Powershell.org. Please take a moment and read the very first post on top of the list of this forum: Read Me Before Posting! You’ll be Glad You Did!.

When you post code, error messages, sample data or console output format it as code, please.
In the “Text” view you can use the code tags “PRE“, in the “Visual” view you can use the format template “Preformatted“. You can go back edit your post and fix the formatting – you don’t have to create a new one.
Thanks in advance.

Running in the context of the user may be possible, but it’s going to require a good chunk of added code. Powershell is meant to administer and get information from remote systems, it’s not designed to run in the context of the remotely logged in user. However, you can try something like this:

https://stackoverflow.com/questions/41902301/run-powershell-command-as-currently-logged-in-user

Not sure exactly how this works as you are remotely executing this, the account you are using to connect is a logged on user.