I’m writing a batch script to pull SCCM site codes from SCCM clients. I’d like to pull the clients site code and compare that to an array of site codes. If there is a match then I’ll uninstall the client. I have the uninstall portion. This has to be done as a batch file.
I can get the site code with the following WMIC command
WMIC /namespace:\\root\ccm path sms_client CALL GetAssignedSite
This produces the following output
Executing (sms_client)->GetAssignedSite()
Method execution successful.
Out Parameters:[abstract]
class __PARAMETERS
{
[out, ID(0): DisableOverride ToInstance] string sSiteCode = "BBB";
[out] uint32 ReturnValue;
};
How can I extract and compare the site code in the batch script – “BBB” in this example.
Here is what I have for Powershell as an example but this has to be a batch file.
$SiteCode = ([wmiclass]'ROOT\ccm:SMS_Client').GetAssignedSite()
$SCCMSiteCodes = @('AAA', 'BBB', 'CCC', 'GGG', 'VVV')
If ($SCCMSiteCodes -Contains $SiteCode.sSiteCode)
{ uninstall SCCM client }
I'll end up running the .bat file with a psexec command against a server list.
Thanks for the help.
Thanks again, dbenham. I modified the code slightly by adding a second IF statement.
SETLOCAL enableDelayedExpansion
SET "SCCMSiteCodes= 'AAA' 'BBB' 'CCC' 'GGG 'VVV' "
FOR /f delims^=^"^ tokens^=2^ eol^= %%A in (
'wmic /namespace:\\root\ccm path sms_client CALL GetAssignedSite^|findstr sSiteCode'
) DO (
IF "!SCCMSiteCodes:'%%A'=!" neq "!SCCMSiteCodes!" (
CALL :TEE SCCM client - Sitecode match found
REM Your uninstall CALL goes here
)
IF "!SCCMSiteCodes:'%%A'=!" equ "!SCCMSiteCodes!" (
CALL :TEE SCCM client - Sitecode match not found
GOTO NOTFOUIND
)
)
I found another scenario that triggers an uninstall and I'm not exactly sure why since it doesn't contain any of the sitecodes. In this case the server has not reached the SCCM managemnent server so it has not received a sitecode.
For these servers, the response to
WMIC /namespace:\\root\ccm path sms_client CALL GetAssignedSite
is
Executing (sms_client)->GetAssignedSite()
ERROR:
Description = Can't enumerate any more, because the associated data is missing
I'm researching but have not come up with an answer yet. Any suggestions?