Sunday, November 18, 2012

Export Bitlocker Recovery Keys for a list of computers

If you want to generate a list of computers and their Bitlocker keys, then you can use this command. This will generate the keys in CSV format:


Adfind -b ou=xxx,ou=xxxxxx,ou=xxxx,ou=xxxxx,dc=xxx,dc=xxxx -csv -csvdelim # -f "(msFVE-RecoveryPassword=*)" msFVE-RecoveryPassword > bitlocker_keys.txt


Replace xxx with correct distinguished names of the required OU.
You need to have access to Bitlocker recovery keys.

Thursday, November 15, 2012

Running VBScripts on Vista/Win 7 64 bit computers

Sometimes while running vbscripts on Win 7 64 bit computers, the script gives errors in creating objects or unable to access shares.

The reason is that vbscripts are being executed as 64 bit scripts.

Some DLLs do not support 64 bits, so the script has to be run wit hthe 32 bit version of WScript.exe from the directory %SystemRoot%\SysWOW64 or the global Registry setting has to be changed:
HKEY_CLASSES_ROOT\VBSFile\Shell\Open\Command
(Standard) from
"%SystemRoot%\System32\WScript.exe" "%1" %*
to
"%SystemRoot%\SysWOW64\WScript.exe" "%1" %*

Wednesday, September 19, 2012

Mssing SCCM Performance Counters

I was facing this strange issue of not able to find all those SMS_**** performance montor counters.

Tried the LODCTR commands and rebooted the server, but it did not help.
Even went into every SMS folder under c:\windows\inf, and run the command to rebuild SMS Counters

Lodctr /R:<filename>. But it didnt work.


Finally, Microsoft support provided me this solution that worked.



Open cmd prompt (run as administrator).
Go to the installation location of ConfigMgr.
Eg:
C:\Program files (x86)\Microsoft Configuration Manager\bin\i386>
Type in the following:
Perfsetup.exe /install /siteserver:<ServerName> SMS_WSUS_SYNC_MANAGER
Eg:
Perfsetup.exe /install /siteserver:SCCMCEN SMS_WSUS_SYNC_MANAGER
Check the PErfsetup.log for any errors.

Once I followed the above steps I was able to see all the Perf Counters for SMS.

For MSSQLServer counters:

Open this registry key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\MSSQLSERVER\Performance
Check the value of PerfINIFile.
Open cmd prompt.
Go to SQL Bin folder - C:\Program Files\Microsoft SQL Server\...Bin
Run this command lodctr sqlctr.ini
And lodctr perf-MSSQLSERVERsqlctr.ini (value found for PerfINIFile).

Restart SQL service.  
 



Wednesday, July 25, 2012

Script to move package to another folder

Recently i was required to move some packages to an 'Archive' folder. Instead of doing this manually, I created this script. The list of packages has to be put into the array in the script:


Option Explicit
'On error resume next

Dim strSMSServer, strSMSSiteCode, strPackageIDs
Dim intSourceFolder, intDestFolder, intObjectType
Dim loc, objSMS
Dim objFolder
Dim arrPackageIDs
Dim retval

strSMSServer   = "xxx"
strSMSSiteCode = "xxx"
strPackageIDs  = "99900048,9990004B..." 'to move more than one, separate with commas

intSourceFolder = 0 'Source Folder (In Production=8, Root=0)
intDestFolder   = 310 'Destination Folder (TobeDeleted = 310)
intObjectType   = 2 '2=Package for type of object

Set loc         = CreateObject("WbemScripting.SWbemLocator")
Set objSMS      = loc.ConnectServer(strSMSServer, "root\SMS\site_" & strSMSSiteCode)

Set objFolder = objSMS.Get("SMS_ObjectContainerItem")
arrPackageIDs = Split(strPackageIDs, ",")

retval = objFolder.MoveMembers(arrPackageIDs, intSourceFolder , intDestFolder , intObjectType)
If Err.Number <> 0 Then
    Wscript.Echo Err.Description
End Ifss

Wscript.echo "Done"

-----

to get the folder numbers, use this:

strSiteCode = "xxx"

Set SWBemlocator  = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = SWBemlocator.ConnectServer(strComputer,"\root\sms\site_" & strSiteCode,UserName,Password)

Dim AdvertisementInfo, objItem
Set AdvertisementInfo = objWMIService.ExecQuery ("select * from SMS_ObjectContainerNode") ' where Name = '" & FolderName & "'")
For Each objItem in AdvertisementInfo
    wscript.echo "The folder node ID for """ & objItem.Name & """ is: " & objItem.ContainerNodeID
Next

Thursday, June 14, 2012

AD Script to list OUs

I created this script to list out all the OUs and count of computers in each OU. You need to run it on a DC, and replace XXX with complete distinguished DC name:

'On Error Resume Next

Const ADS_SCOPE_SUBTREE = 2

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_SUBTREE

objCommand.CommandText = _
    "SELECT ADsPath FROM 'LDAP://xxxx/OU=xx,OU=xx,DC=xx,DC=xx' WHERE objectCategory='organizationalUnit'" 

Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst
Wscript.echo "OU,Count of Computers"
    intCtr = 0
Do Until objRecordSet.EOF
    Set objOU = GetObject(objRecordSet.Fields("ADsPath").Value)
    'Wscript.Echo objOU.distinguishedName
    If Instr(objOU.distinguishedName,"T_Workstations") Then
        Continue
    End If

    objOU.Filter = Array("Computer")
    intCtr=0
    For Each objItem in objOU
        'Wscript.Echo objItem.CN
    intCtr = intCtr + 1
    Next
    Wscript.Echo objOU.distinguishedName & "," & intCtr
   
    objRecordSet.MoveNext
Loop

AD Script to list Sites, Descriptions

Recently, I had to list and dump the sites information from AD. So, I created this script for it:

on error resume next

Set objRootDSE = GetObject("LDAP://RootDSE")
strConfigurationNC = objRootDSE.Get("configurationNamingContext")

strSitesContainer = "LDAP://cn=Sites," & strConfigurationNC
Set objSitesContainer = GetObject(strSitesContainer)
objSitesContainer.Filter = Array("site")
intCtr = 0
For Each objSite In objSitesContainer
    intStart = Instr(objSite.description,"(")
    intEnd = Instr(objSite.description,")")
    'Wscript.echo objSite.description
    strSiteCode = Mid(objSite.description,intStart)

    intStart = Instr(objSite.description,":")
    intEnd = Instr(objSite.description,",")
    strBusiness = Mid(objSite.description,intStart+1, intEnd-intStart-1)

    intStart = InstrRev(objSite.description,"/")
    intEnd = InstrRev(objSite.description,":")
    strLocation = Mid(objSite.description,intStart+1, intEnd-intStart-1)

    intStart = Instr(objSite.description,"/")
    intEnd = InstrRev(objSite.description,"/")
    strCountry = Mid(objSite.description,intStart+1, intEnd-intStart-1)

    WScript.Echo strSiteCode & "-" & strLocation & ";" & objSite.cn &  ";" & strCountry & ";" & strBusiness
    intCtr = intCtr + 1
    'If intcTR = 15 Then Exit For
Next

You need to run in on a DC.