所以我有一个.bat文件,将运行我的powershell脚本与隐藏窗口的原因,其所有显示与图形用户界面。
IF EXIST "%ProgramFiles%"\PowerShell\7\pwsh.exe (
"%ProgramFiles%"\PowerShell\7\pwsh.exe -windowstyle hidden .\ZscalerPosture.ps1
) ELSE (
Powershell.exe -windowstyle hidden .\ZscalerPosture.ps1
)
现在它看起来像这样:
但它不会改变数字或颜色:
现在,改变数字和颜色的代码是:
$DetailsText1.Text = ($properties)[1]
if (($properties)[1] -eq 1) {
$DetailsText1.BackColor = '#43eb34'
}Else{
$DetailsText1.BackColor = 'Red'
}
$DetailsText2.Text = ($properties)[3]
if (($properties)[3] -eq 1) {
$DetailsText2.BackColor = '#43eb34'
}Else{
$DetailsText2.BackColor = 'Red'
}
$DetailsText3.Text = ($properties)[5]
if (($properties)[5] -eq 1) {
$DetailsText3.BackColor = '#43eb34'
}Else{
$DetailsText3.BackColor = 'Red'
}
$DetailsText4.Text = ($properties)[7]
if (($properties)[7] -eq 1) {
$DetailsText4.BackColor = '#43eb34'
}Else{
$DetailsText4.BackColor = 'Red'
}
$DetailsText5.Text = ($properties)[9]
if (($properties)[9] -eq 1) {
$DetailsText5.BackColor = '#43eb34'
}Else{
$DetailsText5.BackColor = 'Red'
}
$DetailsText6.Text = ($properties)[11]
if (($properties)[11] -eq 1) {
$DetailsText6.BackColor = '#43eb34'
}Else{
$DetailsText6.BackColor = 'Red'
}
$DetailsText1.Refresh()
$DetailsText2.Refresh()
$DetailsText3.Refresh()
$DetailsText4.Refresh()
$DetailsText5.Refresh()
$DetailsText6.Refresh()
(note:是的,它现在很乱,我正在清理它)
额外说明:如果我正常运行文件(右击>用PowerShell运行),它工作正常
1条答案
按热度按时间q3qa4bjr1#
所以它不工作的原因是因为.bat试图在powershell7中打开,出于某种原因代码不喜欢这样。所以.bat文件看起来像
这将打开GUI而不显示powershell并按预期工作。