2016-11-23 14 views
-1

現在の状況: 画面の右下にトーストのような通知を表示できるpowershellスクリプトを作成しました。私の唯一の問題は、これがローカルコンピュータでのみ動作することです。この通知をターゲットマシンに表示するにはどうすればよいですか? Active Directoryにマシン名を指定するだけですか?エンタープライズ設定でユーザー/マシンに通知を送信する方法は?

もちろん、私は他の提案があります。私は現在SignalRを読んでいますが、私はSignalRをネイティブデスクトップ上で動作させる方法がわからず、ウェブサイトではありません。完璧な状況は、Windows 10のトースト通知を大量に送信できる通知システムです。

アイデアはありますか?

ここ

私はルーン時間前に次のことを書いている私の現在のスクリプト

Function ShowNotification 
{ 
    [CmdletBinding()] 
    param(
      [string] $Title, 
      [string] $Message, 
      [string] $Image, 
      [string] $Hyperlink 
    ) 
    Add-Type -AssemblyName presentationframework, System.Windows.Forms 

     $screenHeight = Get-WmiObject -Class Win32_DesktopMonitor | Select-Object ScreenHeight 
     $screenWidth = Get-WmiObject -Class Win32_DesktopMonitor | Select-Object ScreenWidth 

     ############################ NOTIFICATION CLIENT GUI ######################################### 

$XAML2 = @' 
<Window Name="Form2" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing" 
     Title="Notification" Height="141.071" Width="504.611" WindowStyle="None" ShowInTaskbar="False" ResizeMode="NoResize" Background="#313130"> 
    <Window.Effect> 
     <DropShadowEffect/> 
    </Window.Effect> 
    <Grid Margin="-99,133.5,-102,54" Background="#313130"> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="238*"/> 
      <ColumnDefinition Width="10*"/> 
      <ColumnDefinition Width="9*"/> 
      <ColumnDefinition Width="190*"/> 
      <ColumnDefinition Width="72*"/> 
      <ColumnDefinition Width="55*"/> 
      <ColumnDefinition Width="132*"/> 
     </Grid.ColumnDefinitions> 
     <Label Name="TitleLabel" Content="HEY" HorizontalAlignment="Left" Margin="110,-127,0,0" VerticalAlignment="Top" Height="35" Width="388" Grid.ColumnSpan="5" Foreground="White" Background="{x:Null}" FontWeight="Regular" FontSize="18" FontFamily="Segoe UI SemiLight"/> 
     <Path Data="M99,-92.5" Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="1" Margin="99,-92.5,0,0" Stretch="Fill" Stroke="Black" VerticalAlignment="Top" Width="1"/> 
     <Image Name="imageBox" Source="<PictureSource>" Grid.Column="5" HorizontalAlignment="Left" Height="120" Margin="0,-114,0,-6" VerticalAlignment="Top" Width="75" Grid.ColumnSpan="2"/> 
     <TextBlock Name="MessageTB" HorizontalAlignment="Left" Margin="116,-87,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Grid.ColumnSpan="5" Height="80" Width="382" Foreground="White" FontFamily="Segoe UI Light" FontSize="14"/> 
    </Grid> 
</Window> 


'@ 

[xml]$XAML2 = $XAML2 -replace "<PictureSource>", $Image 

     ############################################################################################### 

     ############################# CONVERT GUI COMPONENTS TO VARIABLES ############################# 
     $script:window = [Windows.Markup.XamlReader]::Load((New-Object System.Xml.XmlNodeReader $xaml2)) 
     $xaml2.SelectNodes("//*[@Name]") | ForEach-Object { Set-Variable -Name ($_.Name) -Value $window.FindName($_.Name) -Scope Script } 
     ############################################################################################### 

     ############################# EVENT HANDLERS ################################################## 
     $window.Add_MouseDown({ 

      If($Image) 
      { 
       $img = [System.Drawing.Image]::Fromfile($Image); 

       $form = new-object Windows.Forms.Form 
       $form.Text = "Image Viewer" 
       $form.Width = $img.Size.Height; 
       $form.Height = $img.Size.Width; 
       $form.StartPosition = "CenterScreen" 

       $pictureBox = new-object Windows.Forms.PictureBox 
       $pictureBox.Dock = "Fill" 
       $pictureBox.SizeMode = "Zoom" 
       $pictureBox.Width = $img.Size.Width; 
       $pictureBox.Height = $img.Size.Height; 

       $pictureBox.Image = $img; 
       ### HYPERLINK WHEN CLICKING PICTURE ### 
       <# 
       If ($img -and $Hyperlink) 
       { 
        $pictureBox.Add_Click({ 
           ### Opens up IE 
           $ie = New-Object -ComObject InternetExplorer.Application 
           $ie.Navigate($Hyperlink) 
           $ie.Visible = $true 
        }) 
       }#> 

       $form.controls.add($pictureBox) 
       $form.Add_Shown({ $form.Activate() }) 
       $form.ShowDialog() 
      } 

      If ($Hyperlink) 
      { 
           $ie = New-Object -ComObject InternetExplorer.Application 
           $ie.Navigate($Hyperlink) 
           $ie.Visible = $true 
      } 

      $window.Close() 
     }) 

    $TitleLabel.Content = $Title 
    $MessageTB.Text = $Message 

    $window.Left = $([System.Windows.SystemParameters]::WorkArea.Width-$window.Width) 
    $window.Top = $([System.Windows.SystemParameters]::WorkArea.Height-$window.Height) 

$timer = new-object System.Windows.Forms.Timer 
$timer.Interval = 20000 
$timer.Add_Tick({ 
$timer.Stop(); 
    #$timer.Tick -= new EventHandler(formClose_Tick); 
$window.Close() 
}) 

$timer.Start() 
$window.ShowDialog() | Out-Null 

} 
+0

よく、あなたはスクリプトを共有できますか?あなたはトースト通知をどのように呼びますか? – 4c74356b41

答えて

0

である(それは、リモートマシン上で動作します - トーストメッセージが動作する前に、ユーザーがマシン上で署名する必要がありますが、コンソールがロックされているかどうかは関係ありません - サインインする必要があります)。 (トピックスターターが彼自身のコードを提供しなかったので、私はこれを投稿してはいけませんが、今度は例外を作成します)。このスクリプトにはパラメータとして設定されていない変数$ credがあります(この変数には、リモートマシンへのInvoke-Commandのために管理者の資格情報が含まれています)。

Function Invoke-ToastMessage 
{ 
[CmdletBinding()] 
    Param 
     (
     [string]$Message, 
     [string]$Notifier = "Administrators", 
     [string]$ComputerName = $null 
     ) 

[scriptblock]$ToastScriptRemote = { 
$Message = $args[0] 
$Notifier = $args[1] 
# XML Template 
[xml]$XmlTemplate = @" 
<toast scenario="reminder"> 
    <visual> 
    <binding template="ToastGeneric"> 
     <text>Admin Notification</text> 
     <text>$Message</text> 
    </binding> 
    </visual> 
    <actions> 
    </actions> 
</toast> 
"@ 
    # fake load the assemblies 
    [void][Windows.UI.Notifications.ToastNotification,Windows.UI.Notifications,ContentType=WindowsRuntime] 
    [void][Windows.Data.Xml.Dom.XmlDocument,Windows.Data.Xml.Dom,ContentType=WindowsRuntime] 
    $FinalXML = [Windows.Data.Xml.Dom.XmlDocument]::new() 
    $FinalXML.LoadXml($XmlTemplate.OuterXml) 
    ## create the toast 
    $Toast = [Windows.UI.Notifications.ToastNotification]::new($FinalXML) 
    ## Show the TOAST message 
    [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($Notifier).show($Toast) 
    } 

[scriptblock]$ToastScriptLocal = { 
# XML Template 
[xml]$XmlTemplate = @" 
<toast scenario="reminder"> 
    <visual> 
    <binding template="ToastGeneric"> 
     <text>Admin Notification</text> 
     <text>$Message</text> 
    </binding> 
    </visual> 
    <actions> 
    </actions> 
</toast> 
"@ 
    # fake load the assemblies 
    [void][Windows.UI.Notifications.ToastNotification,Windows.UI.Notifications,ContentType=WindowsRuntime] 
    [void][Windows.Data.Xml.Dom.XmlDocument,Windows.Data.Xml.Dom,ContentType=WindowsRuntime] 
    $FinalXML = [Windows.Data.Xml.Dom.XmlDocument]::new() 
    $FinalXML.LoadXml($XmlTemplate.OuterXml) 
    ## create the toast 
    $Toast = [Windows.UI.Notifications.ToastNotification]::new($FinalXML) 
    ## Show the TOAST message 
    [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($Notifier).show($Toast) 
    } 

if (![string]::IsNullOrEmpty($ComputerName)) 
    { 
     Invoke-Command -ComputerName $ComputerName -Credential $cred -ScriptBlock $ToastScriptRemote -ArgumentList $Message,$Notifier 
    } 
    else {$ToastScriptLocal.Invoke()} 
} 
+0

こんにちは。これは機能しますか?なぜなら私はinvoke-commandを呼び出すとスクリプトをうまく動かすが、GUIを表示するスクリプトをポップアップさせることはできないことが分かっているからだ。 –

+0

@bluffそれは動作します。ワオ。私は本当にあなたがGUI上でリモートスクリプトを実行できないと思っていました。表示されたトーストを修正してウェブページを開くか、画像などを表示できるボタンのようにする方法はありますか?ありがとう! –

+0

イメージを埋め込むことができます(UNC共有は機能しませんが、マップされたドライブは機能します)。組み込みのWindowsサウンドを使用します。ボタンを追加することも可能ですが、何かにフックすることができないので、無用です。画像を持つようにXMLを構成する方法については、https://msdn.microsoft.com/en-us/windows/uwp/controls-and-patterns/tiles-and-notifications-adaptive-interactive-toastsのドキュメントを参照してください。それらの中に等。 – bluuf

関連する問題