[英]I have created a custom compliance policy in Endpoint manager but the device statuses are 'Error' instead of 'non-compliant' or 'compliant'
This is the very basic picture I am working with.这是我正在使用的非常基本的图片。 It doesnt show the device as 'compliant' or 'non-compliant', but rather with 'error' or 'pending'.
它不会将设备显示为“合规”或“不合规”,而是显示“错误”或“待定”。 I noticed backslashes used as escape character in the logs.
我注意到日志中用作转义字符的反斜杠。 Could the path be a problem?
路径会不会有问题? Please advise.
请指教。
$filePath = "C:\ProgramData\Autodesk\_PennoniCompliance"
$currentFileName = Get-ChildItem -Path $filePath -Name companyCompliance*.txt
$hash = @{
FileName = $currentFileName
}
Write-Output $hash
return $hash | ConvertTo-Json -Compress
My JSON file has the matching key as in the hashTable 'FileName'我的 JSON 文件具有与哈希表“文件名”中的匹配键
{
"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."
}
]
}
]
}
Now I am looking for the status of 'Compliant' or 'Not Compliant' but instead see 'error' or 'pending'.现在我正在寻找“合规”或“不合规”的状态,而是看到“错误”或“待定”。 I have deployed a Custom compliance policy from a sample and it worked fine so its something with this code.
我已经从一个示例中部署了一个自定义合规性策略,它运行良好,因此它与此代码有关。 I also looked at the intuneManagementExtension logs at the time it failed.
我还查看了失败时的 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}
I just don't know what to make of it.我只是不知道该怎么做。 It looks like the backslash is escaping the absolute path, Im not sure.
看起来反斜杠是 escaping 绝对路径,我不确定。 What I do know is any help would be much appreciated.
我所知道的是任何帮助将不胜感激。
You're getting an object back and passing the whole thing to the output.你得到一个 object 并将整个东西传递给 output。
$currentFileName
could possibly return multiple files, and each of those files has multiple properties. $currentFileName
可能会返回多个文件,并且每个文件都有多个属性。
You can inspect this on your box by passing $currentFileName
to get member to see what what properties are available:您可以通过传递
$currentFileName
来在您的盒子上检查它以获取成员以查看哪些属性可用:
$currentFileName | Get-Member
To get back just the file name (of the first result [0]
) you can do:要仅取回文件名(第一个结果
[0]
的),您可以执行以下操作:
$currentFileName = (Get-ChildItem -Path $filePath -Name companyCompliance*.txt)[0].Name
Just be warned, if Get-ChildItem doesn't return anything, the [0]
will throw an error.请注意,如果 Get-ChildItem 不返回任何内容,则
[0]
将引发错误。 You can use an if block to check the count.您可以使用 if 块来检查计数。
I also removed the Write-Output because that could cause issues.我还删除了 Write-Output,因为这可能会导致问题。
Here's the full solution:这是完整的解决方案:
$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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.