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.