Powershell - Como exibir uma mensagem e salvar a entrada do usuário no arquivo de log

Powershell - Como exibir uma mensagem e salvar a entrada do usuário no arquivo de log

Passei a maior parte do dia pesquisando a maneira melhor e mais simples de fazer isso e não parece haver nenhuma. Encontrei pedaços, mas não consegui fazê-los funcionar com sucesso. Eu simplesmente quero exibir uma mensagem pop-up para o usuário executando um script Powershell. Eu gostaria que o script fizesse o seguinte:

1. The popup would give an action for input by the user, 
2. The message will tell them their computer will be restarted to complete a Windows 1809 upgrade, 
3. The user will click ok and the input, along with the username and machine name will be sent to a log file. 
4. The script would have a timer on it that will restart the computer within 30 minutes whether the input is given or not. 

O código abaixo faz o que eu quero, menos o cronômetro, mas não traz uma mensagem pop-up para o usuário. Apenas fornece a mensagem em um console Powershell. Como posso fazer a mesma coisa, mas em uma mensagem pop-up?

$HostName = $env:COMPUTERNAME
$PatchLocation = "c:\Temp\"
$LogFile = "responses.log"
$LogPath = $PatchLocation + $LogFile
$date = Get-Date

$response = Invoke-Command -ComputerName $HostName -ScriptBlock{ Read-Host "Your computer will be restarted in 30 minutes. Please save your work. Type 'Agree' If you have saved your work"}

"Response for $HostName is $response - $date"|Out-File -FilePath $LogPath -Append

Responder1

Dê uma olhadahttps://jdhitsolutions.com/blog/powershell/2976/powershell-popup/

No recente PowerShell Summit, apresentei uma sessão sobre como adicionar elementos gráficos ao seu script sem a necessidade de WinForms ou WPF. Um dos itens que demonstrei é um pop-up gráfico que pode exigir que o usuário clique em um botão ou ignorá-lo automaticamente após um período de tempo definido. Se isso parece familiar, sim, é nosso velho amigo VBScript e o método Popup do objeto Wscript.Shell. Como o PowerShell pode criar e usar objetos COM, por que não aproveitar isso?

$wshell = New-Object -ComObject Wscript.Shell -ErrorAction Stop
$wshell.Popup("Are you looking at me?",0,"Hey!",48+4)

Responder2

Dando crédito a Hans Hubert Vogts, pelo código que fornece a mensagem pop-up. Ele fornece o pop-up. No entanto, eu precisava que o script fosse enviado para um arquivo de log. Modifiquei o código para fazer isso. Está abaixo.

#https://jdhitsolutions.com/blog/powershell/2976/powershell-popup/
#For reference

$HostName = $env:COMPUTERNAME
$PatchLocation = "c:\Temp\"
$LogFile = "responses.log"
$LogPath = $PatchLocation + $LogFile
$date = Get-Date

$wshell = New-Object -ComObject Wscript.Shell -ErrorAction Stop 
$result = $wshell.Popup("Your Computer will be Restarted in 30 Minutes",30,"Hey!",48+4)

"Response for $HostName is $result - $date"|Out-File -FilePath $LogPath -Append

informação relacionada