Xml PowerShell通知脚本(按钮值返回到PowerShell)

Xml PowerShell通知脚本(按钮值返回到PowerShell),xml,powershell,Xml,Powershell,我想用PowerShell制作第一个脚本,也就是当我解锁电脑然后显示通知时。像这样: 我不知道如何将值返回到PowerShell。例如,当我单击全天返回某物并小睡8.5小时时。我只需在新建按钮选项中插入-取消 这是我的代码: #install BurntTaost $ExecutionPolicy = Get-ExecutionPolicy $GetModule = Get-module if(!($ExecutionPolicy | select-string 'RemoteSigned'

我想用PowerShell制作第一个脚本,也就是当我解锁电脑然后显示通知时。像这样:

我不知道如何将值返回到PowerShell。例如,当我单击全天返回某物并小睡8.5小时时。我只需在
新建按钮
选项中插入
-取消

这是我的代码:

#install BurntTaost
$ExecutionPolicy = Get-ExecutionPolicy
$GetModule = Get-module
if(!($ExecutionPolicy | select-string 'RemoteSigned' -Quiet)) { set-ExecutionPolicy -ExecutionPolicy RemoteSigned -force} else { get-ExecutionPolicy}
if(!($GetModule | select-string 'BurntToast' -quiet )) {install-module -name BurntToast} else { get-module | select-string 'BurntToast' -Quiet}
Import-Module BurntToast

$check_work_time_dir = "$HOME/check_work_time"
#Specify Launcher App ID
$LauncherID = "{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe"

#Load Assemblies
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null
[Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null
$start_time = get-date
$half_time = $start_time.AddHours(4)
$full_time = $start_time.AddHours(9)
$work_time_condition = "Nope"
$end_time
$log_file = get-date -format "dd/MM/yyyy"
$date_year = get-date -format "yyyy"
$date_month = get-date -format "MM"
$full_path = "${check_work_time_dir}\${date_year}\${date_month}"
$log_path ="${full_path}\${log_file}.log"

if( -not (test-path $full_path)) { New-Item $full_path -Type Directory | Out-Null }
if( -not (test-path ${log_path})) { New-Item $log_path -Type file | Out-Null }

# 여기는 첫 선택 구문 <정상 출근 , 반차 출근, 다른시간, 아니요> -> this is korean. it is just my comment
# Speaking of actionable, we're using actions right?
$TextHeading    = New-BTText -Text "Your PC is unlocked"
$TextBody       = New-BTText -Text "Have you arrived at the office now?"
# Speaking of actionable, we're using actions right?
$FirstButton    = New-BTButton -Content 'Full Time' -Dismiss
$SecondButton   = New-BTButton -Content 'Half Time'  -Dismiss
$ThirdButton    = New-BTButton -Content 'Other Time'  -Dismiss
$FourthButton   = New-BTButton -Content 'Nope'  -Dismiss

# Then bind them together
$Binding = New-BTBinding -children $TextHeading, $TextBody

# And remember that these components are visual, but not actionable
$Visual = New-BTVisual -BindingGeneric $Binding

# Don't forget that an action by itself is useless, even a single button needs to become plural
$Actions = New-BTAction -Buttons $FirstButton, $SecondButton, $ThirdButton, $FourthButton

# Now all of the content is together...
$Content = New-BTContent -Visual $Visual -Actions $Actions

# We can submit it to the Operating System
Submit-BTNotification -Content $Content

start-Sleep    -s 5

switch ( $work_time_condition ){
    fulltime  { $end_time = $full_time }
    halftime  { $end_time = $half_time }
    othertime { }
    Nope      { exit 0 }
    default   { exit 0 }
}

$last_30m = $end_time.AddHours(-0.5)

echo "Start : $start_time" > $log_path
echo "Half  : $half_time" >> $log_path
echo "Full  : $full_time" >> $log_path
echo "end   : $end_time" >> $log_path
echo "" >> $log_path
#安装BurntHost
$ExecutionPolicy=获取ExecutionPolicy
$GetModule=Get模块
如果(!($ExecutionPolicy |选择字符串'RemoteSigned'-Quiet)){set ExecutionPolicy-ExecutionPolicy RemoteSigned-force}或者{get ExecutionPolicy}
如果(!($GetModule |选择字符串'BurntToast'-quiet)){install module-name BurntToast}或者{获取模块|选择字符串'BurntToast'-quiet}
导入模块BurntToast
$check_work_time_dir=“$HOME/check_work_time”
#指定启动器应用程序ID
$LauncherID=“{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe”
#加载组件
[Windows.UI.Notifications.ToastNotificationManager,Windows.UI.Notifications,ContentType=WindowsRuntime]|输出空值
[Windows.Data.Xml.Dom.XmlDocument,Windows.Data.Xml.Dom.XmlDocument,ContentType=WindowsRuntime]|输出空值
$start\u time=获取日期
$half_time=$start_time.AddHours(4)
$full\u time=$start\u time.AddHours(9)
$work\u time\u条件=“否”
$end_时间
$log_file=获取日期-格式为“dd/MM/yyyy”
$date\U year=获取日期-格式为“yyyy”
$date\u month=获取日期-格式为“MM”
$full_path=“${check_work_time_dir}\${date_year}\${date_MOUNT}”
$log\u path=“${full\u path}\${log\u file}.log”
if(-not(测试路径$full_path)){New Item$full_path-Type Directory | Out Null}
if(-not(测试路径${log_path})){New Item$log_path-Type file | Out Null}
# 여기는 첫 선택 구문  -> 这是韩语。这只是我的评论
#说到可采取行动,我们正在采取行动,对吗?
$TextHeading=新BTText-文本“您的电脑已解锁”
$TextBody=New BTText-Text“您现在到办公室了吗?”
#说到可采取行动,我们正在采取行动,对吗?
$FirstButton=新建BTButton-内容为“全职”-取消
$SecondButton=新建BTButton-内容“一半时间”-取消
$ThirdButton=新建BTButton-内容为“其他时间”-取消
$FourthButton=新建BTButton-内容“否”-驳回
#然后把它们绑在一起
$Binding=新BTBinding-子项$TextHeading,$TextBody
#请记住,这些组件是可视的,但不是可操作的
$Visual=新BTVisual-BindingGeneric$Binding
#不要忘记一个动作本身是无用的,即使是一个按钮也需要变成复数
$Actions=New BTAction-按钮$FirstButton、$SecondButton、$ThirdButton、$FourthButton
#现在所有的内容都在一起了。。。
$Content=New BTContent-Visual$Visual-Actions$Actions
#我们可以将其提交到操作系统
提交BTNotification-内容$Content
开始睡眠-s5
开关($工作时间\条件){
全职{$end_time=$full_time}
中场时间{$end_time=$half_time}
其他时间{}
否{退出0}
默认值{exit 0}
}
$last_30m=$end_time.AddHours(-0.5)
echo“Start:$Start\u time”>$log\u路径
echo“Half:$Half_time”>>$log_路径
echo“Full:$Full\u time”>>$log\u路径
echo“end:$end\u time”>>$log\u路径
echo”“>>$log\u路径