Powershell script to remove a machine from a collection. HTA help, (or HTML, I'm not picky!)
I asked this in the general form Friday, but haven't gotten any hits so I thought I'd post in my "home" forum! :) If anyone can help, I would appreciate it. Could someone give me a hand with integrating the following powershell into either an .hta or html? I basically need 1 input field named, for example "Machine name". The user would enter the needed variable and the script would run. <------------------------------------- #Populate the below Variables with dyamic data from your orchestrator workflow or set it statically in the code. $SCCMServer = "staticvariable" $SmsSiteCode = "staticvariable" $CollectionID = "staticvariable" $ComputerName = "dynamicvariable" $Collection = Get-WmiObject -Namespace "root\SMS\Site_$SmsSiteCode" -Query "select * from SMS_Collection Where SMS_Collection.CollectionID='$CollectionID'" -computername $SCCMServer $Collection.Get() ForEach ($Rule in $($Collection.CollectionRules | Where {$_.RuleName -eq "$ComputerName"})) { # Get the SMS_R_System object for the rule $ComputerObject = Get-WmiObject -Namespace "root\SMS\Site_$SmsSiteCode" -Query "select * from SMS_R_System where Name='$ComputerName'" -computername $SCCMServer $ResourceID = $ComputerObject.ResourceID $smsObject = Get-WmiObject -Namespace "root\SMS\Site_$SmsSiteCode" -Query "Select * From SMS_R_System Where ResourceID='$ResourceID'" -computername $SCCMServer # If the resource is a agent if($smsObject.Name -eq "$ComputerName") { #Delete the membership rule $Collection.DeleteMemberShipRule($Rule) | out-null } } <--------------------------------------------------------- Thank you for any help in advance!!
May 14th, 2012 8:39am

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

Other recent topics Other recent topics