【问题标题】:I have created a custom compliance policy in Endpoint manager but the device statuses are 'Error' instead of 'non-compliant' or 'compliant'我在端点管理器中创建了自定义合规策略,但设备状态为“错误”而不是“不合规”或“合规”
【发布时间】:2022-07-22 02:58:04
【问题描述】:

这是我正在使用的非常基本的图片。它不会将设备显示为“合规”或“不合规”,而是显示“错误”或“待定”。我注意到日志中用作转义字符的反斜杠。路径会不会有问题?请指教。

$filePath = "C:\ProgramData\Autodesk\_PennoniCompliance"
$currentFileName = Get-ChildItem -Path $filePath -Name companyCompliance*.txt
$hash = @{
    FileName = $currentFileName
}
Write-Output $hash
return $hash | ConvertTo-Json -Compress

我的 JSON 文件具有与 hashTable 'FileName' 中的匹配键

{
    "Rules":[
        {
           "SettingName":"FileName",
           "Operator":"IsEquals",
           "DataType":"String",
           "Operand":"PennoniCompliance_2021-0921.txt",
           "MoreInfoUrl":"https://call4cloud.nl/2021/11/the-last-days-of-custom-compliance/#part1",
           "RemediationStrings":[
              {
                 "Language":"en_US",
                 "Title":"Must update text file suffix.",
                 "Description": "Must update the suffix containing the date (PennoniCompliance_yyyy-mmdd.txt) of the PennoniCompliance text file."
              }
           ]
        }
    ]
}

现在我正在寻找“合规”或“不合规”的状态,但看到的是“错误”或“待定”。我已经从一个示例中部署了一个自定义合规性策略,它运行良好,因此它与此代码有关。我还查看了失败时的 intuneManagementExtension 日志。

{"PolicyId":"0cb83122-b322-45f5-9ab1-8e75c28ce7f5","UserId":"5fc325b8-6b7b-4b95-9e66-df64471366e0","PolicyHash":null,"Result":3,"ResultDetails":null,"InternalVersion":2,"ErrorCode":0,"ResultType":3,"PreRemediationDetectScriptOutput":"{\"FileName\":{\"value\":\"PennoniCompliance_2021-0921.txt\",\"PSPath\":\"Microsoft.PowerShell.Core\\\\FileSystem::C:\\\\ProgramData\\\\Autodesk\\\\_PennoniCompliance\\\\PennoniCompliance_2021-0921.txt\",\"PSParentPath\":\"Microsoft.PowerShell.Core\\\\FileSystem::C:\\\\ProgramData\\\\Autodesk\\\\_PennoniCompliance\",\"PSChildName\":\"PennoniCompliance_2021-0921.txt\",\"PSDrive\":{\"CurrentLocation\":\"WINDOWS\\\\system32\",\"Name\":\"C\",\"Provider\":\"Microsoft.PowerShell.Core\\\\FileSystem\",\"Root\":\"C:\\\\\",\"Description\":\"Windows\",\"MaximumSize\":null,\"Credential\":\"System.Management.Automation.PSCredential\",\"DisplayRoot\":null},\"PSProvider\":{\"ImplementingType\":\"Microsoft.PowerShell.Commands.FileSystemProvider\",\"HelpFile\":\"System.Management.Automation.dll-Help.xml\",\"Name\":\"FileSystem\",\"PSSnapIn\":\"Microsoft.PowerShell.Core\",\"ModuleName\":\"Microsoft.PowerShell.Core\",\"Module\":null,\"Description\":\"\",\"Capabilities\":52,\"Home\":\"C:\\\\WINDOWS\\\\system32\\\\config\\\\systemprofile\",\"Drives\":\"C\"},\"PSIsContainer\":false}}","PreRemediationDetectScriptError":null,"RemediationScriptErrorDetails":null,"PostRemediationDetectScriptOutput":null,"PostRemediationDetectScriptError":null,"RemediationStatus":4,"Info":{"RemediationExitCode":null,"FirstDetectExitCode":0,"LastDetectExitCode":null,"ErrorDetails":null},"TargetType":1,"RunAsAccount":1,"AssignmentFilterIds":null,"BiosMetadata":null} 

我只是不知道该怎么做。看起来反斜杠正在转义绝对路径,我不确定。我所知道的是,任何帮助将不胜感激。

【问题讨论】:

    标签: powershell endpoint intune


    【解决方案1】:

    您正在获取一个对象并将整个内容传递给输出。 $currentFileName 可能会返回多个文件,每个文件都有多个属性。

    您可以通过传递$currentFileName 在您的盒子上检查此内容,以获取成员以查看哪些属性可用:

    $currentFileName | Get-Member
    

    要只取回文件名(第一个结果[0]),您可以这样做:

    $currentFileName = (Get-ChildItem -Path $filePath -Name companyCompliance*.txt)[0].Name
    

    请注意,如果 Get-ChildItem 没有返回任何内容,[0] 将引发错误。您可以使用 if 块来检查计数。

    我还删除了 Write-Output,因为这可能会导致问题。

    这是完整的解决方案:

    $filePath = "C:\ProgramData\Autodesk\_PennoniCompliance"
    $currentFile = Get-ChildItem -Path $filePath -Name companyCompliance*.txt
    if($currentFile.Count -ge 1){
      $currentFileName = $currentFile[0].Name
    }
    else {
      $currentFileName = 'None'
    }
    $hash = @{
        FileName = $currentFileName
    }
    return $hash | ConvertTo-Json -Compress
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-24
      • 2019-10-08
      • 2020-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多