2016-11-23 2 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