Question

Evaluation Code To check if a folder exist or not

  • 30 December 2021
  • 2 replies
  • 50 views

Hi guys,  

I want to use a worklet to install the SCCM client, how would be the evalution code?, when is possible that the machine already has the client installed but pointing to an old sccm server.

This worklet is intended to be used most over remote machines that connect to system center over VPN.

So the evaluation code should check if “C:\Windows\ccmcache” exist or not, and run the remediation code exist or not the folder.

I already has the remediation code ready and tested, just need the evaluation code that allow both conditions,  exist or not the ccmcache folder.

 

i know this code check if the folder exist, but not sure if also will run the remediation code if the folder not exist:

 

if( Test-Path -Path "C:\Windows\ccmcache" )

{

exit 1

}

i Just need that worklet works exist or not the ccmcache folder

 

Apprecciate any help.

regards.


2 replies

Userlevel 1

Hey @Roger_Garcia!

 

Could you post your remediation code? Since the client may already be installed, you could set your evaluation code to always exit 1. Then have your remediation code look for if the client is already installed and delete it before reinstalling it. That way you ensure they’re pointing to the correct SCCM server.

 

Jessica Starkey | Technical Marketing Engineer.

Userlevel 4

This method does require SCCM exists on the host already. It uses the client to determine what Site Code is currently assigned. If it is the new site, good to go, if not run remediation code.

#new site code
$newSiteCode = '002'

$smsClient = New-Object -ComObject Microsoft.SMS.Client

#return current site code
$Result = $smsClient.GetAssignedSite()

#test current site code
if ($Result -eq $newSiteCode)
{
# Good to go
Exit 0
}
Else
{
# Run Remediation Code
Exit 1
}

 

Reply