We help IT Professionals succeed at work.
Get Started

VBS to run on specific OU

444 Views
Last Modified: 2013-12-25
Hi,

I have this script, it can run automaticly on each computer on the computers OU.
I need this script to run on other OU (named UK). what do i have to change in this code in order to implement this?

Thanks!
Set colComputers = GetObject("LDAP://CN=Computers, DC=Domain, DC=com")
set fso=CreateObject("scripting.filesystemobject")
strTargetPath="c:\scripts\"
i=1
 
 
For Each objComputer in colComputers
	strComputer = objComputer.CN
	on error resume next
	set fOut=fso.CreateTextFile(strTargetPath & strComputer & ".txt", true)
	if Err.Number<>0 then
		Err.Clear
		set fOut=fso.CreateTextFile(strTargetPath & "INVALID_NAME" & i & ".txt", true)
		i=i+1
		fOut.WriteLine "Computer name: " & strComputer
		fOut.WriteLine ""
	end if
' ----------
	
	'Sub KBcheck()
Const HKEY_LOCAL_MACHINE = &H80000002
 
'strComputer = "l-yairn"
Set objRegistry = GetObject("winmgmts:\\" & _ 
    strComputer & "\root\default:StdRegProv")
 
strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Hotfix\KB955839"
strValueName = "Installed"
 
objRegistry.GetDwordValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
 
 
If IsNull(strValue) Then
 
      	fOut.WriteLine   "No value - You should install KB955839"
		Wscript.Echo "No value - You should install KB955839"
Else
 
    If strValue = 1 then 
	'intValue = 3
	'objRegistry.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,intValue
	' Wscript.Echo "value exist"
	 fOut.WriteLine  "KB exist"
	 Wscript.Echo  "KB exist"
    End If
 
End If
 
if Err.Number=0 then
		on error goto 0
'end sub
' -----------
	else
		Err.Clear
		Wscript.Echo  "Computer not available"
		'fOut.WriteLine "Computer not available"
	end if
	on error goto 0
	fOut.Close
	set fOut=nothing
Next
set fso=Nothing

Open in new window

Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
This problem has been solved!
Unlock 1 Answer and 9 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE