$missing
是字符串列表,所以
Echo
控制台负责在多行上格式化它们。
MessageBox
要求使用换行符(ASCII 10)连接字符串。
$([String]::Join(([Convert]::ToChar(10)).ToString(), $missing)
该行使用
String.Join Method (System)
[Convert]::ToChar(10)
\n
但是使用它会导致使用文本字符串而不是换行符。我们只是将ASCII代码10转换为一个字符(然后是一个字符串),并使用它连接文件名。
以下是更新后的脚本:
$missing = Compare-Object $capture.BaseName $output.BaseName | Select-Object -ExpandProperty InputObject
If($missing -ne $null){
Write-Host 'Here are the missing file(s):'
Echo $missing
# Send pop up alert
$missingWithNewlines = $([String]::Join(([Convert]::ToChar(10)).ToString(), $missing))
$ButtonType = [System.Windows.MessageBoxButton]::OK
$MessageboxTitle = âPlease Process Filesâ
$Messageboxbody = â
The following are missing:
$missingWithNewlinesâ
$MessageIcon = [System.Windows.MessageBoxImage]::Warning
[System.Windows.MessageBox]::Show($Messageboxbody,$MessageboxTitle,$ButtonType,$messageicon)
}Else{
# Nothing missing
}
结果如下: