我正在 Powershell 中使用 SCSM,但遇到了 if 语句的问题。
我有一个函数,它根据作为变量传递给函数的条件收集数据。例子:
$JMLs1 = collectTickets -crit $JMLCriteria1
Run Code Online (Sandbox Code Playgroud)
collectTickets
是函数,$JMLCriteria1
是通过的标准。
这是collectTickets
函数:
function collectTickets
{
param (
[parameter (Mandatory=$true)]
$crit
)
$fullDate = Get-Date
if ($fullDate.DayOfWeek -eq 'Monday')
{
$olderThan = $fullDate.AddDays(-4)
}
elseif ($fullDate.DayOfWeek -eq 'Tuesday')
{
$olderThan = $fullDate.AddDays(-4)
}
else
{
$olderThan = $fullDate.AddDays(-2)
}
if ($crit -like '$JML*')
{
$data = Get-SCSMObject -Criteria $crit | select 'Id', 'Title', 'LastModified', 'Priority'
}
else
{
$data = Get-SCSMObject -Criteria $crit | …
Run Code Online (Sandbox Code Playgroud) 我正在创建一个脚本,该脚本将根据条件更新 Excel 电子表格。
这就是我目前所拥有的:
if ($endIRs -ne $null) {
$endIRs | ForEach-Object {
try {
$classification = $_.Classification
$priority = $_.Priority
$title = $_.Title
$id = $_.Id
switch ($classification) {
{($_ -eq 'Reports') -and ($priority -eq '1')} {
$GeAppsReportSheet.Cells.Item(8,2).Interior.ColorIndex = 3
$GeAppsReportSheet.Cells.Item(8,2) = 'RED'
}
#more switch statements to go here
}
catch {#catch tickets with $classification not listed}
}
}
Run Code Online (Sandbox Code Playgroud)
一$endIRs
开始保存了过去 12 小时内记录的一系列高优先级“事件”。如果没有,一切都将是默认设置的“绿色”。
我试图通过该语句实现的switch
目标是if (($classification -eq 'Reports') -and ($priority -eq '1')) {'change the cell …