Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Removing Computer from SCCM with Status Filter Rule and Powershell

$
0
0

Hello all.  I have searched high and low, and no solutions seem to help me.  I have a status filter rule in SCCM 2012, which at the completion of an OSD ts, will kick off the following powershell script on the sccm server, which is Server 2012 with POSH v3. it also sends the %msgsys parameter when launching the script:

Param($compname)

if ($compname.StartsWith("MININT"))
    {
    Write "Deleting $compname from SCCM"  
    clear
    $ServerName = "MyServer"
    $SMSSiteCode = "MySite"
    $comp = Get-WmiObject -Namespace "root\SMS\Site_$SmsSiteCode"  -query "select * from sms_r_system where name ='$compname'" -computername $ServerName 
    $comp.psbase.delete()
    }
    Else
        {
        Write "$compname was not deleted from SCCM"
        }

The script works perfectly, if I block param and manually create the variable with computer name.  As I need this to be automated, that will not work.  When I pass the name from SCCM, the param $compname shows as it should in logging, however, I get the following error:

Method invocation failed because
[System.Management.Automation.PSInternalMemberSet] doesn't contain a method
named 'delete'.
At C:\Media\RemoveMinints.ps1:24 char:5
+     $delete.psbase.delete()
+     ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (delete:String) [], RuntimeExc
   eption
    + FullyQualifiedErrorId : MethodNotFound

I have tried $comp | ForEach-Object { $_.Delete() } but it does not delete the computer.  No errors, but does not function either.  My eyes are going crossed on this one.  Any suggestions would be helpful.



Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>