powershell Power shell脚本存储应答和返回

ih99xse1  于 2023-04-21  发布在  Shell
关注(0)|答案(1)|浏览(128)

我想知道是否有人可以帮助我,我试图编译一个PS脚本,显示一个问题的弹出框,我希望它存储的答案,并返回给我。我设法得到这个脚本的弹出问题,但找不到返回答案的方法,这可能是通过发送电子邮件回也许?

Add-Type

-AssemblyName PresentationCore,PresentationFramework

$msgBody = "This is a question type your answer"

$msgTitle = "Confirm Reboot"

$msgButton = 'YesNoCancel'

$msgImage = 'Question'

$Result = [System.Windows.MessageBox]::Show($msgBody,$msgTitle,$msgButton,$msgImage)

Write-Host "The user chose: $Result [" ($result).value__ "]"

尝试了脚本的工作,需要的答案返回到我的电子邮件

m528fe3b

m528fe3b1#

根据我的评论。
这就是PowerShell邮件cmdlet允许您执行的操作。只需查看PowerShell控制台/伊势/VSCode示例中的帮助示例。请参阅邮件命令---

Get-Command -Name '*mail*'

参见示例:

Get-Help -Name 'Send-MailMessage' -Examples
# Results
<#
SYNOPSIS
    Sends an email message.
    
    
    -- Example 1: Send an email from one person to another person --
    
    Send-MailMessage -From 'User01 <user01@fabrikam.com>' -To 'User02 <user02@fabrikam.com>' -Subject 'Test mail'
#>

获取cmdlet详细信息:

Get-Help -Name 'Send-MailMessage' -Detail

找到要下载/安装和使用的邮件模块:

Find-module -Name '*mail*'

所以,根据你所说的。总而言之,它可能只是这样:

Add-Type -AssemblyName PresentationCore, 
                       PresentationFramework

$msgBody   = "Make a selection"
$msgTitle  = "Confirm Reboot"
$msgButton = 'YesNoCancel'
$msgImage  = 'Question'
$Result    = [System.Windows.MessageBox]::Show($msgBody,$msgTitle,$msgButton,$msgImage)

$MailProperties = @{
    From    = 'User01 <user01@fabrikam.com>'
    To      = 'User02 <user02@fabrikam.com>'
    Subject = 'Results from user app response'
    Body    = "The user chose: $Result"
}
Send-MailMessage @MailProperties

好吧,你还需要给予它一个邮件服务器。
根据我们最后的评论交流更新。
注意:我使用了一个名为***Variable Squeezing***的PowerShell功能,以便将值分配给变量并同时输出到屏幕上。这在代码中不需要执行您所要执行的操作,但它会在稍后的代码中处理变量内容之前显示变量内容。

Add-Type -AssemblyName PresentationCore, 
                    PresentationFramework

$msgBody   = "Make a selection"
$msgTitle  = "Confirm Reboot"
$msgButton = 'YesNoCancel'
$msgImage  = 'Question'
($Result   = [System.Windows.MessageBox]::Show($msgBody,$msgTitle,$msgButton,$msgImage))
# Results
<#
Yes
#>

Add-Type -AssemblyName PresentationCore, 
                    PresentationFramework

$msgBody   = "Make a selection"
$msgTitle  = "Confirm Reboot"
$msgButton = 'YesNoCancel'
$msgImage  = 'Question'
($Result   = [System.Windows.MessageBox]::Show($msgBody,$msgTitle,$msgButton,$msgImage))
# Results
<#
No
#>

Add-Type -AssemblyName PresentationCore, 
                    PresentationFramework

$msgBody   = "Make a selection"
$msgTitle  = "Confirm Reboot"
$msgButton = 'YesNoCancel'
$msgImage  = 'Question'
($Result   = [System.Windows.MessageBox]::Show($msgBody,$msgTitle,$msgButton,$msgImage))
# Results
<#
Cancel
#>

相关问题