如何解决Powershell写消息
我在此问题上遇到了麻烦
我需要在脚本末尾添加一条额外的消息。该脚本可以正常运行,并且结果正常。 有人可以给我一些帮助吗?我不明白我在做什么错。
使用这部分代码,我得到了结果:
If ($Media -and !$Written){
Compare-Object -ReferenceObject $Media -DifferenceObject $FNa | Select @{Name="File"; Expression={$_.InputObject}},@{Name="Evaluation";Expression= {$Lookup[$_.SideIndicator]}},@{Name="Session";Expression={$Session}} | Tee-Object -FilePath "C:\Scripts\...\Evaluation.txt"
}
Elseif($Written -and !$Media){Compare-Object -ReferenceObject $Written -DifferenceObject $FNa | Select @{Name="File";Expression={$_.InputObject}},@{Name="Evaluation";Expression= {$Lookup[$_.SideIndicator]}},@{Name="Session";Expression={$Session}} | Tee-Object -FilePath "C:\Scripts\...\Evaluation.txt"
}
Elseif($Media -and $Written){$Media+=$Written;Compare-Object -ReferenceObject $Media -DifferenceObject $FNa | Select @{Name="File";Expression={$_.InputObject}},@{Name="Evaluation"; Expression={$Lookup[$_.SideIndicator]}},@{Name="Session";Expression={$Session}} | Tee-Object -FilePath "C:\Scripts\...\Evaluation.txt"
}
结果:
File Evaluation Session
---- ---------- -------
MHE_notes20091.pdf Only in Xip Notes_I
MHE_notes2009.pdf Only in Opex Notes_I
但是我需要这个简单的警告,以便出现在控制台上并导出到txt文件:
Write-Warning -Message "These Sessions are empty ==>>" ; $Names | Tee-Object -FilePath "C:\Scripts\...\Evaluation.txt" -Append
我正在得到这个结果:(
WARNING: These Sessions are empty ==>>
File Evaluation Session
---- ---------- -------
MHE_notes20091.pdf Only in Xip Notes_I
MHE_notes2009.pdf Only in Opex Notes_I
MHENKAF060213_1
MHENKDV050603_2
MHENKDV061106_2
MHENKMD050216_1
MHENKMD050216_2
我想要这个:
WARNING: These Sessions are empty ==>>
MHENKAF060213_1
MHENKDV050603_2
MHENKDV061106_2
MHENKMD050216_1
MHENKMD050216_2
File Evaluation Session
---- ---------- -------
MHE_notes20091.pdf Only in Xip Notes_I
MHE_notes2009.pdf Only in Opex Notes_I
感谢您的帮助!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。