PowerShell Discovery script

Hello,

I am currently working on some configuration items and I am having some problems with my discovery script. Basically, I'm trying to see if a file exists, and run the remediation script if it doesn't. Here is my discovery script:

Function Check-Path {
    $return = Test-Path 'C:\Users\Public\Desktop\File.txt'
    return $return
}

Function Check-True {
    if (Check-Path) {
        Return $true
    } else {
        Return $false
    }
}
 
Return Check-True

Now I can't tell if this script is working correctly or not through Config manager. When I run it locally, it does detect if the file exists. The part I'm not sure on is the text that says, "Use the echo command to return the script value to Configuration Manager" in the Edit discovery script window. I'm not sure what result it is expecting.

Since it is a Boolean, it should be just looking for a true or false, but when the file is absent, it isn't running the remediation script. (Here is the sanitized remediation script)

Copy-Item '\\server\publicshare\file" -Destination "C:\Users\Public\Desktop"

Here are the settings for my compliance rules:

I'm guessing that the discovery script isn't sending the correct information to Config Manager in order to detect if the file exists. Please let me know if you need more information.

Thanks,

Ed

July 21st, 2015 2:43pm

The script is run in system context so \\server\publicshare will be accessed by using the computer account of the client. Would a client be able to access it?
Free Windows Admin Tool Kit Click here and download it now
July 21st, 2015 3:10pm

The easiest method to see what's working is to go to the client machine and opening the Configuration Manager Properties. Go to the tab Configurations and use View Report for your configuration baseline.
July 21st, 2015 3:10pm

The script is run in system context so \\server\publicshare will be accessed by using the computer account of the client. Would a client be able to
Free Windows Admin Tool Kit Click here and download it now
July 22nd, 2015 7:11am

The easiest method to see what's working is to go to the client machine and opening the Configuration Manager Properties. Go to the tab Configurations and use View Report for your configuration
July 22nd, 2015 7:14am

Take a look at the client log files for more information about the failure. The related log files are mentioned here: https://technet.microsoft.com/en-us/library/hh427342.aspx?#BKMK_CompSettingsLog
Free Windows Admin Tool Kit Click here and download it now
July 22nd, 2015 8:38am

ConfigMgr doesn't change the system policy, it simply runs scripts with specified restriction policy the same as you would if running PowerShell.exe with the -executionpolicy parameter. Without looking at the logs files, everything is just a guess.
Free Windows Admin Tool Kit Click here and download it now
July 22nd, 2015 11:33am

ConfigMgr doesn't change the system policy, it simply runs scripts with specified restriction policy the same as you would if running PowerShell.exe with the -executionpolicy parameter. Without looking at the logs files, everything is jus
July 22nd, 2015 12:43pm

CIDownloader.log just shows the script being downloaded, not anything about it being run. Check CIAgent.log or DCMAgent.log (I don't remember which).
Free Windows Admin Tool Kit Click here and download it now
July 22nd, 2015 4:25pm

CIDownloader.log just shows the script being downloaded, not anything about it being run. Check CIAgent.log or DCMAgent.log (I don't rememb
July 23rd, 2015 10:22am

Powershell will return a exit code when it`s done running. if it was a success it would return 0.

SO i would change the data type to Integer.

The returned value of the script should be equal to 0 for compliance.

I would change the script to this 

if(!(Test-Path C:\Users\Public\Desktop\File.txt)){exit 1}
exit 0

You test to see is it doesn't exist and if it doesn't exist the script will end 1 witch tell SCCM that the compliance is not OK.

This is the way i always did my compliance since powershell compliance.

You will find good info about it here:http://blog.kloud.com.au/2014/08/12/powershell-detection-method-for-sccm-2012-application-compliance-management/
Free Windows Admin Tool Kit Click here and download it now
July 23rd, 2015 10:36am

Powershell will return a exit code when it`s done running. if it was a success it would return 0.

SO i would change the data type to Integer.

The returned value of the script should be equal to 0 for compliance.

I would change the script to this 

if(!(Test-Path C:\Users\Public\Desktop\File.txt)){exit 1}
exit 0

You test to see is it doesn't exist and if it doesn't exist the script will end 1 witch tell SCCM that the compliance is not OK.

This is the way i always did my compliance since powershell compliance.

You will find good info about it here:http://blog.kloud.com.au/2014/08/12/powershell-detection-method-for-sccm-2012-application-compliance-management/
July 23rd, 2015 2:34pm

Powershell will return a exit code when it`s done running. if it was a success it would return 0.

SO i would change the data type to Integer.

The returned value of the script should be equal to 0 for compliance.

I would change the script to this 

if(!(Test-Path C:\Users\Public\Desktop\File.txt)){exit 1}
exit 0

You test to see is it doesn't exist and if it doesn't exist the script will end 1 witch tell SCCM that the compliance is not OK.

This is the way i always did my compliance since powershell compliance.

You will find good info about it here:http://blog.kloud.com.au/2014/08/12/powershell-detection-method-for-sccm-2012-application-compliance-management/

Frederick, thanks so much. Your advice was correct and my detection script works. Here it is:

if (Test-Path 'C:\Users\Public\Desktop\file.txt'){
Return 0}
Else {Return 1}

By changing the values to Integers, it resolved my issue. I incorrectly assumed that since PowerShell knows $True and $False, if I returned one of those values, it would accept that as a Boolean. Such a simple fix, but now that allows me to continue my work.

Thanks again,

Ed

Free Windows Admin Tool Kit Click here and download it now
July 24th, 2015 9:57am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics