如何修复“小数”

时间:2018-12-28 20:02:07

标签: powershell

我正在从SharePoint列表中提取信息。一切正常,但列表的结果对于year列打印为2018.0000000,而current_high和current_medium的打印结果分别为4.0000000和26.0000000。我已经尝试了所有功能浮点,十进制,四舍五入。但是我无法取整0。有人可以帮我吗?

Select-Object ows_Year, ows_Status, ows_App, ows_cycle, ows_Current_Critical,
    ows_Current_High, ows_Current_Medium, @{Name='Result'; Expression={
        ForEach-Object {
            $d1 = (Get-Date).ToString("MM-dd")
            $d2 = (Get-Date 2018-12-28).ToString("MM-dd")

            if ($d1 -eq $d2) {
                if ($_.ows_Cycle -eq 'Cycle 1') {
                    if ([int]($_.ows_Current_Critical) -eq 0 -and [int]($_.ows_Current_High) -eq 0 -and [int]($_.ows_Current_Medium) -eq 0) {
                        'Pass'
                    } else {
                        'Fail'
                    }
                }
            }
        }
    }} |

1 个答案:

答案 0 :(得分:0)

即使评论中的人已经指出了如何执行此类任务,也可能会有些混乱。所以在一起:

Select-Object @{Name='ows_Year'; Expression={[Int]$_.ows_Year}}, ows_Status, ows_App, ows_cycle, ows_Current_Critical,
    ows_Current_High, ows_Current_Medium, @{Name='Result'; Expression={
        ForEach-Object {
            $d1 = (Get-Date).ToString("MM-dd")
            $d2 = (Get-Date 2018-12-28).ToString("MM-dd")

            if ($d1 -eq $d2) {
                if ($_.ows_Cycle -eq 'Cycle 1') {
                    if ([int]($_.ows_Current_Critical) -eq 0 -and [int]($_.ows_Current_High) -eq 0 -and [int]($_.ows_Current_Medium) -eq 0) {
                        'Pass'
                    } else {
                        'Fail'
                    }
                }
            }
        }
   }} |