Pages

Showing posts with label SCCM / SMS VBScript. Show all posts
Showing posts with label SCCM / SMS VBScript. Show all posts

SCCM - Roger Zander Sourceforge Tools

Roger Zander Sourceforge Tools And Utilities

SMS/SCCM Peer2Peer AddOn

SMSTorrent is a Peer2Peer AddOn for SMS2003/SCCM2007 Clients. SMS/SCCM Clients are able to share the local Package cache with other Clients using the BitTorrent filesharing protocol.

http://sourceforge.net/projects/smstorrent

SMS Site Settings tweak

SMSSettings provides a GUI to modify SMS2003 (Microsoft System Management Server 2003) Site Settings which are not accessible over the normal SMS Admin Interface.

http://sourceforge.net/projects/smssettings

Screen Lock

This Tool does lock the Screen, Mouse and Keyboard for a specified time.

http://sourceforge.net/projects/screenlock

SMS Client Center

Troubleshoot and manage SMS 2003 advanced clients

http://sourceforge.net/projects/smsclictr

SMS 2003 Offline Hardware Inventory

Capture SMS2003 Hardware Inventory on Systems without Network connectivity or Systems without an SMS Agent installed. This Tool creates a DDR (DataDiscoveryRecord) and an IDMIF File for each scanned system.

http://sourceforge.net/projects/smshwinv

Secure Autologon

Enable Windows Autologon without a cleartext password in the Registry. The password will be stored by the Local Security Authority (LSA).

http://sourceforge.net/projects/autologon

SMS2003 Object Backup

Backup and restore a definable set of SMS 2003 Objects (Packages, Programs, Advertisements, Collections...). SMSObjBackup can also be used for Site Migration (Objects can be moved to another SMS Primary Site Server)

http://sourceforge.net/projects/smsobjbackup

SMS 2003 Adv.Client local policy import

A command line tool to assign local software distribution policies to an SMS 2003 Advanced Client. The Software will be installed independent of collection memberships.

http://sourceforge.net/projects/smspolimp

SMS CloneDP

Manage the assigned Software Packages of a Microsoft SMS (SystemManagementServer) 2003 DistributionPoint

http://sourceforge.net/projects/smsclonedp

SMS 2003 Software Request Web Form

SMS 2003 Software Request Web Form with a simple Workflow (mail/web based).

http://sourceforge.net/projects/smsswreq

SMS Collection Commander

Initiate SMS 2003 advanced client actions on a collection: Ping, WakeUp, HW/SW Inventory, ReRun Advertisements, Show logged on user, Download/Refresh Policy, Repair SMS Agents, Import Clients to the Collection...

http://sourceforge.net/projects/smscollctr

SMS OSD Program Import

SMSOSDXML extends the SMS 2003 Admin Console to import OSD Program-Settings based on a XML File. SMS OSD automatically creates such XML Files (SMSDeploy.xml) for each OSD Program created in the Admin Console.

http://sourceforge.net/projects/smsosdxml

SMS Package Dependency Viewer

Show "Microsoft System Management Server 2003" Software Package dependencies in a TreeView.

http://sourceforge.net/projects/smsdepview

script that has WMI connection error will skip it and move to next

strComputer = "MYcomputername"

Set objExcel = CreateObject("Excel.Application")

objExcel.Visible = True

objExcel.Workbooks.Add

intRow = 2

objExcel.Cells(1, 1).Value = "Logon Name"

objExcel.Cells(1, 2).Value = "Full Name"

objExcel.Cells(1, 3).Value = "Description"

objExcel.Cells(1, 4).Value = "Domain"

objExcel.Cells(1, 5).Value = "Password Changeable"

objExcel.Cells(1, 6).Value = "Password Required"

objExcel.Cells(1, 7).Value = "Password Expires"

objExcel.Cells(1, 8).Value = "Account Disabled"

objExcel.Cells(1, 9).Value = "Account Locked Out"

On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
If err.Number <> 0 then
       Call Wscript.echo("Error has occurred connecting to WMI on workstation: " & strComputer)
End if

Set colItems = objWMIService.ExecQuery("Select * from Win32_UserAccount")

For Each objItem in colItems

objExcel.Cells(intRow, 1).Value = objItem.Name

objExcel.Cells(intRow, 2).Value = objItem.FullName

objExcel.Cells(intRow, 3).Value = objItem.Description

objExcel.Cells(intRow, 4).Value = objItem.Domain

If objItem.PasswordChangeable = True Then

objExcel.Cells(intRow, 5).Value = "Yes"

objExcel.Cells(intRow, 5).Font.ColorIndex = 10

Else   

objExcel.Cells(intRow, 5).Value = "No"

objExcel.Cells(intRow, 5).Font.ColorIndex = 3

End If

If objItem.PasswordRequired = True Then

objExcel.Cells(intRow, 6).Value = "Yes"

objExcel.Cells(intRow, 6).Font.ColorIndex = 10

Else   

objExcel.Cells(intRow, 6).Value = "No"

objExcel.Cells(intRow, 6).Font.ColorIndex = 3

End If

If objItem.PasswordExpires = True Then

objExcel.Cells(intRow, 7).Value = "Yes"

objExcel.Cells(intRow, 7).Font.ColorIndex = 10

Else   

objExcel.Cells(intRow, 7).Value = "No"

objExcel.Cells(intRow, 7).Font.ColorIndex = 3

End If

If objItem.Disabled = True Then

objExcel.Cells(intRow, 8).Value = "Yes"

objExcel.Cells(intRow, 8).Font.ColorIndex = 10

Else   

objExcel.Cells(intRow, 8).Value = "No"

objExcel.Cells(intRow, 8).Font.ColorIndex = 3

End If

If objItem.Lockout = True Then

objExcel.Cells(intRow, 9).Value = "Yes"

objExcel.Cells(intRow, 9).Font.ColorIndex = 10

Else   

objExcel.Cells(intRow, 9).Value = "No"

objExcel.Cells(intRow, 9).Font.ColorIndex = 3

End If

intRow = intRow + 1

Next

objExcel.Range("A1:I1").Select

objExcel.Selection.Interior.ColorIndex = 19

objExcel.Selection.Font.ColorIndex = 11

objExcel.Selection.Font.Bold = True

objExcel.Cells.EntireColumn.AutoFit

MsgBox "Done"

'Below script to create number of computers in AD--for testing

'Below script to create number of computers in AD--for testing

'==============================================================================
'
' Description: This script creates multiple sequential computer accounts
' in an AD OU. It appends a 3 digit number to the base name starting with
' the number entered at the prompt.
' ==============================================================================
Option Explicit
'Define Constants
Const ADS_SCOPE_ONELEVEL = 1
'Declare Variables
Dim DQ
Dim strAdmin
Dim intRecord
Dim objShell
Dim objNetwork
Dim intWarn
Dim objRootDSE
Dim strADsPath
Dim objConnection
Dim objCommand
Dim strOUPath
Dim objRecordSet
Dim strBaseName
Dim intRecordMax
Dim bEnabled
Dim objOU
Dim strNewComputerName
Dim objNewComputer
Dim strDomainDN
Dim strDomainFQDN
Dim intOULevel
Dim strSearchADsPath
Dim intStartNumber
'Set variables
DQ = Chr(34)
'Create Objects
Set objShell = CreateObject("Wscript.Shell")
Set objNetwork = CreateObject("WScript.NetWork")
'Verifies script was run using Cscript, and if not relauches it using Cscript
If Not WScript.FullName = WScript.Path & "\cscript.exe" Then

objShell.Popup "Relaunching script with Cscript in 5 seconds...", 5, _
"Script Host Message", 48

objShell.Run "cmd.exe /k " & WScript.Path & "\cscript.exe //NOLOGO " & _
DQ & WScript.scriptFullName & DQ, 1, False

Script.Quit 0
End If

'Warn User
intWarn = MsgBox("This will make changes to AD." & VbCr & _
"Are you sure you want to do this?", 308, "ID 10 T Check")
'308 = Yes/No (4) + 'Exclaimation (48) + Default Button 2 (256)
If intWarn = vbNo Then

WScript.Quit 0
End If
'Construct an ADsPath to the Current Domain with rootDSE
Set objRootDSE = GetObject("LDAP://rootDSE")
strADsPath = "LDAP://" & objRootDSE.Get("defaultNamingContext")
'Convert domain Distinguished Name to FQDN format
strDomainDN = objRootDSE.Get("defaultNamingContext")
strDomainFQDN = Replace(Replace(strDomainDN, "DC=", ""), ",", ".")
'Connect to Active Directory
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_ONELEVEL
'Prompt for Path to OU
Do

strOUPath = _
InputBox("Please enter the path to the OU where the computer accounts " & _
" will be created - Seperate OUs With a \", "OU Path Input", "TopOU\SubOU")
If strOUPath = False Then
WScript.Quit

End If
Loop Until strOUPath <> ""


'Split OU path by OU
strOUPath = UCase(strOUPath)
strOUPath = Split(strOUPath, "\")


'Prepare variables for search
intOULevel = 0
strSearchADsPath = strADsPath


'Search through each OU level in path provided
For intOULevel = 0 To UBound(strOUPath)

objCommand.CommandText = "SELECT ADsPath FROM '" & strSearchADsPath & _
"'" & " WHERE objectCategory='organizationalUnit' AND Name = '" & _
strOUPath(intOULevel) & "'"

Set objRecordSet = objCommand.Execute

'Verify OU was found

If objRecordSet.EOF Then

WScript.echo "OU named " & strOUPath(intOULevel) & _
" not found, Exiting script."

WScript.quit

Else

objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strSearchADsPath = objRecordSet.Fields("ADsPath").Value
objRecordSet.MoveNext
Loop
End If
Next
'Get current username to use in description field
strAdmin = objNetwork.UserName
'Prompt for the base computer name
Do
strBaseName = _
InputBox("Please enter the base computer name to use for new accounts:", _
"Base Computer Name", "TestPC")
If strBaseName = False Then
WScript.Quit
End If
Loop Until strBaseName <> ""
strBaseName = UCase(strBaseName)
'Prompt for starting computer number
Do

intStartNumber = _
InputBox("Please enter the beginning number to use in computer names:", _
"Starting Computer Number", "001")
If intStartNumber = False Then

WScript.Quit

End If
Loop Until intStartNumber <> ""
intStartNumber = CInt(intStartNumber)
intRecord = intStartNumber
'Prompt for number of accounts to be created
Do

intRecordMax = _
InputBox("Please enter the number of accounts to be created", _
"Count Input", "10")
If intRecordMax = False Then

WScript.Quit

End If
Loop Until intRecordMax <> ""
intRecordMax = CInt(intRecordMax)


'Bind to OU that computers will be created in
Set objOU = GetObject(strSearchADsPath)

'Create the user accounts
Do Until intRecord = intRecordMax + intStartNumber
intRecord = Right("000" & intRecord, 3)
strNewComputerName = strBaseName & intRecord
WScript.Echo "Creating " & strNewComputerName
Set objNewComputer = objOU.Create("Computer", "cn= " & strNewComputerName)
objNewComputer.Put "samAccountName", strNewComputerName & "$"
objNewComputer.Put "userAccountControl", 4096
objNewComputer.Put "description", "Account created: " & Date() & " by: " _
& strAdmin
objNewComputer.SetInfo 'Writes settings to AD
intRecord = intRecord + 1
Loop

WScript.Echo
WScript.echo "Finished creating computer accounts."

Collection of Computers based on Users

Collection of Computers based on Users

 
SMS has a nice feature that allows you to create a collection based on users. That way when a users logs into a computer SMS will then run an advertisement for whatever computer they are on. The problem is maybe you want to have a collection of computers not the users. The worst flaw this the collection query I have created below and using collections based on users is that if a person logs in to another machine, for whatever reason, SMS will find them and push software to them.
That in mind, here is a collection that will take any OU group of users and create a collection of computers.


---------------------------------------
select SMS_R_System.ResourceID,SMS_R_System.ResourceType,SMS_R_System.Name,SMS_R_System.SMSUniqueIdentifier,SMS_R_System.ResourceDomainORWorkgroup,SMS_R_System.Client from SMS_R_System inner join SMS_G_System_COMPUTER_SYSTEM on SMS_G_System_COMPUTER_SYSTEM.ResourceID = SMS_R_System.ResourceId where SMS_G_System_COMPUTER_SYSTEM.UserName in (select UniqueUserName from SMS_R_User where UserOUName = "xxxx /SECURITY USERS & GROUPS" )
--------------------------------------
Windows User account and group discovery must be enabled and run on your server to use this.

How does this work. It first grabs the list of users. Then matches them to the comptuers that SMS currently sees them logged into. To change this to Last Logged in user you need to change the SMS_G_System_Computer_System to SMS_R_System.LastLogonUserName for computers. This will give you last logged in user.

"Limit to Collection" for all your computer Workstations or further limit it to based on departments

If you don't know what group then you can create a query of just (select UniqueUserName from SMS_R_User where UserOUName = "") click values until you have the value you need and paste it into the larger query.
-------------------
Thanks,
http://sccm07.blogspot.com/

Creating 1000 User Accounts

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--Creating 1000 User Accounts
 
Set objRootDSE = GetObject("LDAP://rootDSE")
Set objContainer = GetObject("LDAP://cn=Users," & _
    objRootDSE.Get("defaultNamingContext"))

For i = 1 To 1000
    Set objLeaf = objContainer.Create("User", "cn=UserNo" & i)
    objLeaf.Put "sAMAccountName", "UserNo" & i
    objLeaf.SetInfo
Next

WScript.Echo "1000 Users created."
 
 
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Creating an Active Directory User Account-------------------------------------------------------------------------
 
Creates a user account in Active Directory. This script only creates the account, it does not enable it.
Set objOU = GetObject("LDAP://OU=management,dc=fabrikam,dc=com") Set objUser = objOU.Create("User", "cn=MyerKen") objUser.Put "sAMAccountName", "myerken" objUser.SetInfo
 
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Creating a User, a Group, and an OU

 

Demonstration script that: 1) creates a new Active Directory organizational unit; 2) creates a new user account and new security group; and, 3) adds the new user as a member of that security group.

Set objDomain = GetObject("LDAP://dc=fabrikam,dc=com") Set objOU = objDomain.Create("organizationalUnit", "ou=Management") objOU.SetInfo   Set objOU = GetObject("LDAP://OU=Management,dc=fabrikam,dc=com") Set objUser = objOU.Create("User", "cn= AckermanPilar") objUser.Put "sAMAccountName", "AckermanPila" objUser.SetInfo   Set objOU = GetObject("LDAP://OU=Management,dc=fabrikam,dc=com") Set objGroup = objOU.Create("Group", "cn=atl-users") objGroup.Put "sAMAccountName", "atl-users" objGroup.SetInfo   objGroup.Add objUser.ADSPath
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Deleting a User Account from Active Directory

----------------------------------------------------------------------
Deletes the user account for MyerKen from the HR organizational unit in a hypothetical domain named fabrikam.com.
Set objOU = GetObject("LDAP://ou=hr,dc=fabrikam,dc=com") objOU.Delete "user", "cn=MyerKen"

Determining When an Account Expires


Returns the expiration date for a user account.
On Error Resume Next Set objUser = GetObject _   ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")   dtmAccountExpiration = objUser.AccountExpirationDate    If err.number = -2147467259 Or _  dtmAccountExpiration = "1/1/1970" Then   WScript.echo "No account expiration specified" Else   WScript.echo "Account expiration:" & _     objUser.AccountExpirationDate End If
 
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Determining When a Password Expires
 
Determines the date when a user password will expire.
Const SEC_IN_DAY = 86400 Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000   Set objUserLDAP = GetObject _   ("LDAP://CN=myerken,OU=management,DC=fabrikam,DC=com") intCurrentValue = objUserLDAP.Get("userAccountControl")   If intCurrentValue and ADS_UF_DONT_EXPIRE_PASSWD Then   wscript.echo "The password does not expire." Else   dtmValue = objUserLDAP.PasswordLastChanged    Wscript.echo "The password was last changed on " & _   DateValue(dtmValue) & " at " & TimeValue(dtmValue) & VbCrLf & _   "The difference between when the password was last set" & VbCrLf & _   "and today is " & int(now - dtmValue) & " days"   intTimeInterval = int(now - dtmValue)      Set objDomainNT = GetObject("WinNT://fabrikam")   intMaxPwdAge = objDomainNT.Get("MaxPasswordAge")   If intMaxPwdAge < 0 Then     WScript.Echo "The Maximum Password Age is set to 0 in the " & _       "domain. Therefore, the password does not expire."   Else     intMaxPwdAge = (intMaxPwdAge/SEC_IN_DAY)     Wscript.echo "The maximum password age is " & intMaxPwdAge & " days"     If intTimeInterval >= intMaxPwdAge Then       Wscript.echo "The password has expired."     Else       Wscript.echo "The password will expire on " & _       DateValue(dtmValue + intMaxPwdAge) & " (" & _       int((dtmValue + intMaxPwdAge) - now) & " days from today" & ")."     End If   End If End If

Determining When a Password was Last Set


Identifies the last time a user password was set.
Set objUser = GetObject _     ("LDAP://CN=myerken,OU=management,DC=Fabrikam,DC=com") dtmValue = objUser.PasswordLastChanged WScript.echo "pwdLastSet is: " & dtmValue

Determining User Account Status


Identifies whether a user account is enabled or disabled.
Set objUser = GetObject _   ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")   If objUser.AccountDisabled = FALSE Then       WScript.Echo "The account is enabled." Else       WScript.Echo "The account is disabled." End If

Determining When a User Account Expires


Reports the date that the MyerKen Active Directory user account expires.
On Error Resume Next Set objUser = GetObject _     ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com") dtmAccountExpiration = objUser.AccountExpirationDate    If Err.Number = -2147467259 Or dtmAccountExpiration = "1/1/1970" Then     WScript.Echo "No account expiration specified" Else     WScript.Echo "Account expiration: " & objUser.AccountExpirationDate End If
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Moving a User Account


Moves a user account from one OU to another.
Set objOU = GetObject("LDAP://ou=sales,dc=na,dc=fabrikam,dc=com") objOU.MoveHere _     "LDAP://cn=BarrAdam,OU=hr,dc=na,dc=fabrikam,dc=com", vbNullString
 
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Requiring a Password Change


Forces a user to change their password the next time they logon.
Set objUser = GetObject _     ("LDAP://CN=myerken,OU=management,DC=Fabrikam,DC=com") objUser.Put "pwdLastSet", 0 objUser.SetInfo
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Retrieving User Account Account Properties


Retrieves user account attributes found on the Account page of the user account object in Active Directory Users and Computers.
 On Error Resume Next Set objUser = GetObject _   ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com") objUser.GetInfo   strUserPrincipalName = objUser.Get("userPrincipalName") strSAMAccountName = objUser.Get("sAMAccountName") strUserWorkstations = objUser.Get("userWorkstations")   Set objDomain = GetObject("LDAP://dc=fabrikam,dc=com") objDomain.GetInfoEx Array("dc"), 0 strDC = objDomain.Get("dc")   WScript.echo "userPrincipalName: " & strUserPrincipalName WScript.echo "sAMAccountName: " & strSAMAccountName WScript.echo "UserWorkstations: " & strUserWorkstations WScript.echo "dc: " & strDC
 
 
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Unlocking an Active Directory User Account


Unlocks the MyerKen Active Directory user account.
Set objUser = GetObject _     ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com") objUser.IsAccountLocked = False objUser.SetInfo
 
 
 

Using VBScript to PLAY with Active Directory

Using VBScript to Export All Objects in the Marketing OU

In this example, you use a text editor such as Notepad to create a VBScript program. The script searches the Marketing OU and creates a text file that lists all of the user objects and a subset of their attributes.

To create the export script

  1. Copy the following text into your text editor:

    'Global variables  Dim oContainer  Dim OutPutFile  Dim FileSystem  'Initialize global variables  Set FileSystem = WScript.CreateObject("Scripting.FileSystemObject")  Set OutPutFile = FileSystem.CreateTextFile("marketing.txt", True)  SetoContainer=GetObject("LDAP://OU=marketing,DC=reskit,DC=com")  'Enumerate Container  EnumerateUsers oContainer  'Clean up  OutPutFile.Close  Set FileSystem = Nothing  Set oContainer = Nothing  WScript.Echo "Finished"  WScript.Quit(0)  Sub EnumerateUsers(oCont)  Dim oUser  For Each oUser In oCont  Select Case LCase(oUser.Class)  Case "user"  If Not IsEmpty(oUser.distinguishedName) Then  OutPutFile.WriteLine "dn: " & oUser.distinguishedName  End If   If Not IsEmpty(oUser.name) Then   OutPutFile.WriteLine "name: " & oUser.Get ("name")  End If  'need to do this because oUser.name would get back the Relative   Distinguished name (i.e. CN=Jo Brown)  If Not IsEmpty(oUser.st) Then   OutPutFile.WriteLine "st: " & oUser.st  End If  If Not IsEmpty(oUser.streetAddress) Then   OutPutFile.WriteLine "streetAddress: " & oUser.streetAddress  End If  Case "organizationalunit" , "container"  EnumerateUsers oUser  End Select  OutPutFile.WriteLine   Next  End Sub 
  2. Save the file as Export.vbs.

  3. At the command prompt type export.vbs and press Enter. This creates a file named Marketing.txt, which contains a list of users and some of their attributes, such as distinguished name, name, state, and street address.

With appropriate modification, this script can be used with any application that supports COM and Visual Basic technologies. Such applications include Microsoft Visual Basic, Microsoft Excel, and Microsoft Access. Scripting can also be hosted by Internet Explorer and Internet Information Services 5.0, which is part of Windows 2000 Server.

Using VBScript to Modify All Objects in the Marketing OU

In this example, the Marketing organization has moved to a new office address. A simple VBScript program is used to perform a batch modification for all user objects in the Marketing organization. The script alters the state, street, locality, and postal code attributes.

  1. Copy the following text into your text editor:

    Dim  oContainer Set  oContainer=GetObject("LDAP://  OU=marketing,DC=reskit,DC=com")  ModifyUsers oContainer  'cleanup  Set oContainer = Nothing  WScript.Echo "Finished"  Sub ModifyUsers(oObject)  Dim oUser oObject.Filter = Array("user") For Each oUser in oObject oUser.Put "st","New York" oUser.Put "streetAddress","825 Eighth Avenue" oUser.Put "postalCode","10019" oUser.Put "l","New York" oUser.SetInfo Next  End Sub 
  2. Save the file as Modify.vbs.

  3. At the command prompt, type modify.vbs and press Enter. This processes all objects in the Marketing organizational unit and modifies all users, altering the state, street address, postal code, and locality attributes.

Using VBScript to Create a User Object in the Marketing OU

In this example, you use VBScript to add a new user to the Marketing organization. This example illustrates how easy it is to use ADSI and VBScript to programmatically access the directory. Note that in this example, only a limited set of attributes are configured during the user creation.

To create the script and add the user

  1. Copy the following text into your text editor:

    Dim oContainer 'Parent container  of new   user Dim  oUser 'Created user  'Get parentcontainerSetoContainer=GetObject("LDAP://OU=marketing,  DC=reskit,DC=com")  'Create user  Set oUser = oContainer.Create("User","CN=Jo Brown")  'Assign properties values to user  oUser.Put "samAccountName","Jo"  oUser.Put "givenName","Jo"  oUser.Put "sn","Brown"  oUser.Put "userPrincipalName","jo@reskit.com"  oUser.SetInfo  'Clean up  Set oUser = Nothing  Set oContainer = Nothing  WScript.Echo "Finished" 
  2. Save the file as Adduser.vbs.

  3. At the command prompt, type adduser.vbs and press Enter. This creates a new user named Jo Brown in the Marketing OU.

Using VBScript to Delete a User

In this example, you use VBScript to delete a user from the Marketing organization.

  1. Copy the following text into your text editor:

    Dim oContainer 'Parent container of object to be  deleted 'Get parent  container Set  oContainer=GetObject("LDAP://OU=marketing,  DC=reskit,DC=com")  'Delete user  oContainer.Delete "user","CN=Jo Brown"  'Clean up  Set oContainer = Nothing  WScript.Echo "Finished" 
  2. Save the file as Deluser.vbs.

  3. At the command prompt, type deluser.vbs and press Enter. This deletes the user Jo Brown from the Marketing OU.
    -------------------
    Thanks,
    http://sccm07.blogspot.com/

Enable File and Printer Sharing Through Windows Firewall

Set objFirewall = CreateObject("HNetCfg.FwMgr")
Set objPolicy = objFirewall.LocalPolicy.CurrentProfile

Set colServices = objPolicy.Services
Set objService = colServices.Item(0)
objService.Enabled = TRUE
 

-------------------
Thanks,
http://sccm07.blogspot.com/

Excelent Artical for WMI Troubleshooting Tips

WMI Troubleshooting Tips
 
 

-------------------
Thanks,
http://sccm07.blogspot.com/

VB Script Drive Space Check on list of System

 
 
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add
intRow = 2
 
objExcel.Cells(1, 1).Value = "Machine Name"
objExcel.Cells(1, 2).Value = "Drive"
objExcel.Cells(1, 3).Value = "Total Size"
objExcel.Cells(1, 4).Value = "Used Space"
objExcel.Cells(1, 5).Value = "Free Space"
objExcel.Cells(1, 6).Value = "Free Space Percentage"
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("MachineList.txt", 1)
 
Do Until objFile.AtEndOfStream
strComputer = objFile.ReadLine
Set objWMIService = GetObject("winmgmts://" & strComputer)
 
On Error Resume Next
Set colDisks = objWMIService.ExecQuery("Select * From Win32_LogicalDisk Where DriveType = 3")
For Each objDisk In colDisks
objExcel.Cells(intRow, 1).Value = Ucase(strComputer)
objExcel.Cells(intRow, 2).Value = objDisk.DeviceID
objExcel.Cells(intRow, 3).Value = (FormatNumber(objDisk.Size/ 1024^3, 1)) & " GB"
objExcel.Cells(intRow, 4).Value = (FormatNumber(objDisk.Size/ 1024^3, 1) - FormatNumber(objDisk.FreeSpace/ 1024^3, 1)) & " GB"
objExcel.Cells(intRow, 5).Value = (FormatNumber(objDisk.FreeSpace/ 1024^3, 1)) & " GB"
objExcel.Cells(intRow, 6).Value = FormatPercent(objDisk.FreeSpace/objDisk.Size, 0)
 
If FormatPercent(objDisk.FreeSpace/objDisk.Size, 0) <= "25%" Then
objExcel.Cells(intRow, 6).Font.ColorIndex = 3
Else
End If
 
intRow = intRow + 1
Next
Loop
 
objExcel.Range("A1:F1").Select
objExcel.Selection.Interior.ColorIndex = 19
objExcel.Selection.Font.ColorIndex = 11
objExcel.Selection.Font.Bold = True
objExcel.Cells.EntireColumn.AutoFit
 
MsgBox "Done"
 
 

-------------------
Thanks,
http://sccm07.blogspot.com/

vb script To Clear SCCM / SMS CCM / Cache Folder

To Clear SCCM / SMS CCM / Cache Folder
 
 
' Script to Clear SMS cache files
on error resume next
dim oUIResManager
dim oCache
dim oCacheElement
dim oCacheElements
set oUIResManager = createobject("UIResource.UIResourceMgr")
if oUIResManager is nothing then
'      wscript.echo "Couldn't create Resource Manager - quitting"
     wscript.quit
end if
set oCache=oUIResManager.GetCacheInfo()
if oCache is nothing then
     set oUIResManager=nothing
'      wscript.echo "Couldn't get cache info - quitting"
     wscript.quit
end if
set oCacheElements=oCache.GetCacheElements
'wscript.echo "There are " & oCacheElements.Count & " cache elements"
'wscript.echo
' ***** Begin CLEAR CACHE *****
for each oCacheElement in oCacheElements
oCache.DeleteCacheElement(oCacheElement.CacheElementID)
next
' ***** End CLEAR CACHE *****
' ***** Clean up *****
set oCacheElements=nothing
set oUIResManager=nothing
set oCache=nothing

-------------------
Thanks,
http://sccm07.blogspot.com/

SMS / SCCM Cleint health find Script

here is the Batch file script for SCCM / SMS Clients health along with Last hardware scan report sent time and lastheartbeat time stamp it will show you in the command window this will help you to know the status of Client agent.
 
====================================================================================
@echo off
@echo Client Version  Last Hardware Inventory  Hours Since Last HINV
osql.exe -S SCCMDBSERVERNAME -d SMS_Sitecode -h-1  -E   -Q"set nocount on select Distinct cast(Client_Version0 as char(20)),cast(max(TimeStamp) as char(30)) as hinvDate,datediff(hh,max(TimeStamp),getdate()) as hoursLame from v_r_system,v_GS_WORKSTATION_STATUS where v_r_system.ResourceID = v_GS_WORKSTATION_STATUS.ResourceID and Name0 like '%1' group by Client_Version0"
==================================================================================================
 
 
Simple save above script into .bat file and give the computer name after the batch file and run
 
like
client.bat systemname
 
Yes.............Life is a batch, and then you FLY -------------------
 

SCCM Client Installation Script:-- batch file program

SCCM Client Installation Script:--
 
here is my SCCM Client Installation batch file script.
 
================================================================================================================================================================================
ECHO *********** %1 runing X copy kil.exe
xcopy /y kill.exe \\%1\admin$
psexec \\%1 -c  kill.exe "kill.exe ccmexec.exe"
ECHO *********** %1 Copy dependent files to client admin$
 
xcopy /y ccmsetup.exe \\%1\admin$
ECHO *********** %1 Uninstall SCCM Cleint
psexec \\%1 -c  kill.exe "kill.exe ccmsetup.exe"
psexec \\%1 \\%1\ADMIN$\ccmsetup.exe /uninstall

ECHO *********** %1 Install SCCM Client
psexec \\%1 \\%1\ADMIN$\ccmsetup.exe fsp=SCCMSERVER smssitecode=auto
 
================================================================================================================================================================================
 

-------------------
Thanks,
http://sccm07.blogspot.com/

SCCM Client SUP registry Value Check Script

To find SCCM Client have the SUP server Registry key value status
 
This script will check Weather the Client system is scanning properly with SUP server or not
============================================================================================================================================================================================================================================================
On Error Resume Next
Const HKEY_LOCAL_MACHINE = &H80000002
Set Fso = CreateObject("Scripting.FileSystemObject")
Set InputFile = fso.OpenTextFile("MachineList.Txt")
Do While Not (InputFile.atEndOfStream)
strComputer = InputFile.ReadLine
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate"
strValueName = "WUServer"
objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
If IsNull(dwValue) Then
    Wscript.Echo "The registry key does not exist. (" & dwValue & ") and computer name" & StrComputer
Else
    Wscript.Echo "The registry key exists. (" & dwValue & ") and computer name" & StrComputer
End If
Loop
''''HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate
 
============================================================================================================================================================================================================================================================

-------------------
Thanks,
http://sccm07.blogspot.com/

VBS Script To Copy A File To A Remote Machine

From Myitforum
 
VBS Script To Copy A File To A Remote Machine
 

-------------------
Thanks,
http://paddymaddy.blogspot.com/

File and Print Enable

 

Set objFirewall = CreateObject("HNetCfg.FwMgr")
Set objPolicy = objFirewall.LocalPolicy.CurrentProfile

Set colServices = objPolicy.Services
Set objService = colServices.Item(0)
objService.Enabled = True

-------------------
Thanks,
http://paddymaddy.blogspot.com/

System Info OS and Service Pack Level

' **************************
' ServerInfo.vbs
' Collects OS and SP info
' List of systems must be in same directory as script
' Run using cscript
' **************************
' Name of Input File
strInputFile = "Syslist.txt"
' Name of Output File
strOutputFile = "ServerInfo.csv"

' Create file system object
set objFSO = CreateObject("Scripting.FileSystemObject")
' Check for Existing Output file, Create output file
If  objFSO.FileExists(strOutputFile) Then
   Wscript.echo "You must delete or remove " &  strOutputFile & " from this directory prior to running script"
   wscript.quit
End If
set objOutputFile = objFSO.OpenTextFile(strOutputFile, 2 , True)
If objFSO.FileExists(strInputFile) Then
  set objInStream = objFSO.OpenTextFile(strInputFile, 1)
' Begin reading input file
Set objWebmLocator = CreateObject("WbemScripting.SWbemLocator")
On Error Resume Next
Do While objInStream.AtEndOfStream <> True
 strComputer = objInStream.Readline
 'Wscript.echo ("Connecting to " & strComputer)
 Set objWMI = GetObject("winmgmts:" _
   & "{impersonationLevel=impersonate}!\\" _
   & strComputer & "\root\cimv2")
 
 If Err.number <> 0 Then
  Err.clear
  Set objWMI = objWebmLocator.ConnectServer(strComputer, "root\CIMV2", strUser, strPassword)
 End If
 If Err.Number <> 0 Then
  objOutputFile.Writeline(strComputer & ",Unavailable")
  'WScript.echo ("Connection Failed")
 Else
  Set colOS = objWMI.ExecQuery("Select Caption From Win32_OperatingSystem")
  Set colSP = objWMI.ExecQuery("Select CSDVersion From Win32_OperatingSystem")
 
  intOSCount = 0
  intSPCount = 0
 
  For Each objOS In colOS
   intOSCount = intOSCount + 1
   strOSVal = Replace(objOS.Caption, ",", " ")
  Next
  For Each objSP in colSP
   intSPCount = intSPCount + 1
   strSPVal = objSP.CSDVersion
  Next
  If intOSCount + intSpCOunt > 2 Then
   strVerified = "Unconfirmed"
  Else
   strVerified = "Confirmed"
  End If
  objOutputFile.Writeline(strComputer & "," & strOSVal & "," & strSPVal & "," & strVerified)

 End If
 Err.Clear
 
Loop
End IF
wscript.echo ("Script Complete")
wscript.quit

-------------------
Thanks,
http://paddymaddy.blogspot.com/

WMI Connectivity Check

Set objExcel = CreateObject("Excel.Application")

objExcel.Visible = True

objExcel.Workbooks.Add

intRow = 2

 

objExcel.Cells(1, 1).Value = "Machine Name"

objExcel.Cells(1, 2).Value = "Status"

objExcel.Cells(1, 3).Value = "Error Number"

objExcel.Cells(1, 4).Value = "Hex Error Number"

objExcel.Cells(1, 5).Value = "Error Description"

 

Set Fso = CreateObject("Scripting.FileSystemObject")

Set InputFile = fso.OpenTextFile("MachineList.Txt")

Do While Not (InputFile.atEndOfStream)

strComputer = InputFile.ReadLine

 

On Error Resume Next

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\Wmi")

objExcel.Cells(intRow, 1).Value = UCase(strComputer)

 

If Err.Number <> 0 Then

objExcel.Cells(intRow, 2).Value = "Error"

objExcel.Cells(intRow, 3).Value = Err.Number

objExcel.Cells(intRow, 4).Value = Hex(Err.Number)

ElseIf Err.Number = 0 Then

objExcel.Cells(intRow, 2).Value = "Success"

objExcel.Cells(intRow, 5).Value = "No Errors"

Err.Clear

End If

 

If Err.Number = 462 Then

objExcel.Cells(intRow, 5).Value = "Machine Not Found"

ElseIf Err.Number = "-2147217394" Then

objExcel.Cells(intRow, 5).Value = "WMI Class Not Found"

ElseIf Err.Number = "-2147217405" Then

objExcel.Cells(intRow, 5).Value = "Access Denied"

Err.Clear

End If

 

If objExcel.Cells(intRow, 2).Value = "Error" Then

objExcel.Cells(intRow, 2).Font.ColorIndex = 3

Else

objExcel.Cells(intRow, 2).Font.ColorIndex = 10

End If

 

intRow = intRow + 1

Loop

 

objExcel.Range("A1:E1").Select

objExcel.Selection.Interior.ColorIndex = 19

objExcel.Selection.Font.ColorIndex = 11

objExcel.Selection.Font.Bold = True

objExcel.Cells.EntireColumn.AutoFit

 

MsgBox "Done"


-------------------
Thanks,
http://paddymaddy.blogspot.com/

Admin$ check

Set objExcel = CreateObject("Excel.Application")

objExcel.Visible = True

objExcel.Workbooks.Add

intRow = 2

 

objExcel.Cells(1, 1).Value = "Machine Name"

objExcel.Cells(1, 2).Value = "Admin Share Exists"

 

Set Fso = CreateObject("Scripting.FileSystemObject")

Set InputFile = fso.OpenTextFile("MachineList.Txt")

Do While Not (InputFile.atEndOfStream)

strComputer = InputFile.ReadLine

 

On Error Resume Next

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colShares = objWMIService.ExecQuery("Select * from Win32_Share Where Name = 'ADMIN$'")

 

objExcel.Cells(intRow, 1).Value = UCase(strComputer)

If colShares.Count > 0 Then

objExcel.Cells(intRow, 2).Value = "Yes"

Else

objExcel.Cells(intRow, 2).Value = "No"

End If

If Err.Number <> 0 Then

objExcel.Cells(intRow, 2).Value = Err.Description

Err.Clear

End If

intRow = intRow + 1

 

objExcel.Range("A1:B1").Select

objExcel.Selection.Interior.ColorIndex = 19

objExcel.Selection.Font.ColorIndex = 11

objExcel.Selection.Font.Bold = True

objExcel.Cells.EntireColumn.AutoFit

loop

 

Wscript.Echo "Done"


-------------------
Thanks,
http://paddymaddy.blogspot.com/

Remote Systems Discovery Data Collection Cycle Client agent initiate

On Error Resume Next
Dim oCPAppletMgr
Set oCPAppletMgr = CreateObject("CPApplet.CPAppletMgr")
Dim oClientActions
Set oClientActions = oCPAppletMgr.GetClientActions()
Dim oClientAction
For Each oClientAction In oClientActions
If oClientAction.Name = "Discovery Data Collection Cycle" Then
oClientAction.PerformAction
End If
If oClientAction.Name = "Request & Evaluate Machine Policy" Then
oClientAction.PerformAction
End If
Next

-------------------
Thanks,
http://paddymaddy.blogspot.com/

RoboCopy VBS Script


VBS script with source and destination folder input dialog boxes as well as hard coding the RoboCopy command line switches opposed to issuing the commands from the command prompt
 
 
 

Set objShell = CreateObject("Wscript.Shell")

 

objSource = InputBox("Enter Source")

objDestination = InputBox("Enter Destination")

 

objCommand = "RoboCopy.Exe " & Chr(34) & objSource & Chr(34) & " " & Chr(34) & objDestination & Chr(34) & " /e /r:1 /w:2"

objShell.Run(objCommand)

 

MsgBox "Done"