Link to home
Start Free TrialLog in
Avatar of Glenn M
Glenn MFlag for United States of America

asked on

Import content of text file into powershell script before executing?

I need a way to simply the <text> portion of my Powershell Script that makes a TOAST command. I'm trying to prevent people from making mistakes to the script when being edited.

Is there a way to import the body of a text file and have it imported into the PowerShell script where you find  <text> *** </text> ?


Here is my PS so far:

$app = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]

$Template = [Windows.UI.Notifications.ToastTemplateType]::ToastImageAndText01

#Gets the Template XML so we can manipulate the values
[xml]$ToastTemplate = ([Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent($Template).GetXml())

[xml]$ToastTemplate = @"
<toast launch="action=viewAlarm&amp;alarmId=3" scenario="alarm">

  <visual>
    <binding template="ToastGeneric">
      <text>* Notification *</text>
      
<text>ALERT - Faxing Services are in the Cloud, It's Raining and therefore could faxing no longer works. Stay Tuned for more Information!</text>
<image placement="appLogoOverride" hint-crop="circle" src="https://picsum.photos/64?image=000"/>
            <image placement="hero" src="http://finalbca.16mb.com/noti2.png"/>
    </binding>
  </visual>

  <actions>

     <action
      activationType="system"
      arguments="snooze"
      content=""/>

    <action
      activationType="background"
      arguments="dismiss"
      content="Dismiss"/>

  </actions>

</toast>
"@

$ToastXml = New-Object -TypeName Windows.Data.Xml.Dom.XmlDocument
$ToastXml.LoadXml($ToastTemplate.OuterXml)

$notify = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($app)

$notify.Show($ToastXml)

Open in new window

SOLUTION
Avatar of footech
footech
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Glenn M

ASKER

Both solutions are correct and helpful. Thank you!