Custom asset field report


Im still learning Syncro.

As a test I want to be able to pull a report in a pdf or csv that shows if Windows Defender service exsists

I have made a custom field named “Windows Defender” and this is my script:

Import-Module $env:SyncroModule

$service = Get-Service -Name 'Windows Defender Advanced Threat Protection Service' -ErrorAction SilentlyContinue
if($service -eq $null)
    Set-Asset-Field -Name "Windows Defender" -Value false 
} else {
    Set-Asset-Field -Name "Windows Defender" -Value true 

When I run my report “Windows Defender” field is empty. What am I doing wrong?

To start with, try putting $null on the left.
See Powershell: Everything you wanted to know about $null for more info

$null not being on the left is not your issue, while $null being on the left is recommended and the standard, it’s not causing your issue here.

What kind of field did you make your custom field?

Also, seems strange you would just check for the service existing versus checking the status of it, such as running, etc.

I made it as a text field:

Ahh well that screenshot shows the issue.

Your custom field name is “Windows Defender service running”

In your script you have set asset field -name “Windows Defender”. That’s why it’s not working. Your names must match.

If “Windows Defender” is a Check Box data type, try:

    Set-Asset-Field -Name "Windows Defender" -Value $false
} else {
    Set-Asset-Field -Name "Windows Defender" -Value $true

It’s not, he said it was text, and I told him the problem already lol. He has the custom field named different than what he’s calling it in the script.

I made it as a text field:

Hi and thanks.

The script part was actually my first edition. I have since changed the custom field name. But it did still nok work. However I found the problem. I need to run the script on all assets before running the report. Else the report does not know the value.

I thought the report would run the script on the assets.