It´s a script for removing pxe advertisement from computers. All you need to do is to run the script and enter the computername you would like to clear.
Much easier than going into the console, finding the correct collection, rightclicking...
REM Code written by WMMAYMS - 2010
SiteServer = "<SITESERVERNAME>"
provSiteCode = "<SITECODE>"
strComputer = Inputbox("Enter Computer Name to the computer that you would like to reset","Reseting PXE")
If Len(strComputer) = 0 Then
'do nothing
Else
Set objLocator = CreateObject("WbemScripting.SWbemLocator")
Set objSMS = objLocator.ConnectServer(SiteServer , "root/sms/site_" & provSiteCode)
'get the resource ID of the computer
intResourceID = GetResourceID(strComputer)
end if
Function GetResourceID(strComputerName)
Set colResourceIDs = objSMS.ExecQuery _
("select ResourceID from SMS_R_System where Name = '" & _
strComputer & "'")
for each objResID in colResourceIDs
GetResourceID = objResID.ResourceID
next
End Function
'Remove pxe adv from computer with intResourceID as resourceID
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.
Thought I would share this script with you guys.
It´s a script for removing pxe advertisement from computers. All you need to do is to run the script and enter the computername you would like to clear.
Much easier than going into the console, finding the correct collection, rightclicking...
REM Code written by WMMAYMS - 2010
SiteServer = "<SITESERVERNAME>"
provSiteCode = "<SITECODE>"
strComputer = Inputbox("Enter Computer Name to the computer that you would like to reset","Reseting PXE")
If Len(strComputer) = 0 Then
'do nothing
Else
Set objLocator = CreateObject("WbemScripting.SWbemLocator")
Set objSMS = objLocator.ConnectServer(SiteServer , "root/sms/site_" & provSiteCode)
'get the resource ID of the computer
intResourceID = GetResourceID(strComputer)
end if
Function GetResourceID(strComputerName)
Set colResourceIDs = objSMS.ExecQuery _
("select ResourceID from SMS_R_System where Name = '" & _
strComputer & "'")
for each objResID in colResourceIDs
GetResourceID = objResID.ResourceID
next
End Function
'Remove pxe adv from computer with intResourceID as resourceID
set conexion = Connect(SiteServer, "", "")
ClearPxeAdvertisementResource conexion, intResourceID
Function Connect(server, userName, userPassword)
On Error Resume Next
Dim net
Dim localConnection
Dim swbemLocator
Dim swbemServices
Dim providerLoc
Dim location
Set swbemLocator = CreateObject("WbemScripting.SWbemLocator")
swbemLocator.Security_.AuthenticationLevel = 6 'Packet Privacy
' If the server is local, don't supply credentials.
Set net = CreateObject("WScript.NetWork")
If UCase(net.ComputerName) = UCase(server) Then
localConnection = true
userName = ""
userPassword = ""
server = "."
End If
' Connect to the server.
Set swbemServices= swbemLocator.ConnectServer _
(server, "root\sms",userName,userPassword)
If Err.Number<>0 Then
Wscript.Echo "Couldn't connect: " + Err.Description
Connect = null
Exit Function
End If
' Determine where the provider is and connect.
Set providerLoc = swbemServices.InstancesOf("SMS_ProviderLocation")
For Each location In providerLoc
If location.ProviderForLocalSite = True Then
Set swbemServices = swbemLocator.ConnectServer _
(location.Machine, "root\sms\site_" + _
location.SiteCode,userName,userPassword)
If Err.Number<>0 Then
Wscript.Echo "Couldn't connect:" + Err.Description
Connect = Null
Exit Function
End If
Set Connect = swbemServices
Exit Function
End If
Next
Set Connect = null ' Failed to connect.
End Function
Sub ClearPxeAdvertisementResource(connection,resourceID)
On Error Resume Next
Dim resources
Dim InParams
' Set up the Resource array parameter.
resources = Array(1)
resources(0) = resourceID
Set InParams = connection.Get("SMS_Collection").Methods_("ClearLastNBSAdvForMachines").InParameters.SpawnInstance_
InParams.ResourceIDs = resources
connection.ExecMethod "SMS_Collection","ClearLastNBSAdvForMachines", InParams
if Err.number <> 0 Then
WScript.Echo "Failed to clear PXE advertisement for resource: " & resourceID
Exit Sub
End If
End Sub
Save everything in red as a .vbs file and then edit the first to lines "Siteserver" and "provSiteCode" to match your environment.
Note that you still need the correct sccm permissions to be able to do this..
Cheers
Share this post
Link to post
Share on other sites