september 2010 - Posts

[VBS] - Scripting for OCS (AD Parameters)

A few month ago I had to create a script to automate the proccess of enabling and configuring users for OCS in Active Directory.

I used VBScript for this. MOst part is conventional... however, I had to change the meeting policy from default to something else, this part was tricky.

Enough talking: here you can enjoy the part to change the policy:




'************************************POLICY CHANGE***************************************

        strMeetingPolicy="CN={5DC1A974-C49C-477C-A3F7-E54EECEBE3A9},CN=Policies,CN=RTC Service,CN=Microsoft,CN=System,DC=yourdomain,DC=local"      
        strMeetingPolicyDN1="B:8:01000000:"&strMeetingPolicy
        objUser.put "msRTCSIP-UserPolicy", strMeetingPolicyDN1


        '************************************POLICY CHANGE***************************************


==> Go first in AD and check the values under the Policies (Domain ==> System ==> Microsoft ==> RTC Service ==> Policies)


Pro Memory: here are the most common used parameters for OCS configuration:

 ' The msRTCSIP-OptionFlags attribute specifies the different options that are enabled For

                ' the user. It's a bit-mask value of type integer. Each option is represented by a bit.
                ' Valid value types are:
                ' 1: Enabled for public IM connectivity
                ' 2: Reserved
                ' 4: Reserved
                ' 8: Reserved
                ' 16: RCC (Remote Call Control) enabled [telephony]
                ' 64: AllowOrganizeMeetingWithAnonymousParticipants
                ' 128: UCEnabled (enable user for unified communications)
                ' 256: EnabledForEnhancedPresence
                ' 512: RemoteCallControlDualMode
                ' 1024: Enable auto-attendant
                ' Example: 449 = 256 (Enhanced presence) + 128 (UC enabled) + 64 (anonym. participants) + 1 (public IM)
                nOptionFlags = 320


                objUser.put "msRTCSIP-PrimaryUserAddress", strPrimaryUserAddress
                objUser.put "msRTCSIP-FederationEnabled", bFederationEnabled
                objUser.put "msRTCSIP-ArchivingEnabled", nArchivingEnabled
                objUser.put "msRTCSIP-InternetAccessEnabled", bInternetAccessEnabled
                objUser.put "msRTCSIP-Line", strLine
                objUser.put "msRTCSIP-OptionFlags", nOptionFlags
                objUser.put "msRTCSIP-PrimaryHomeServer", strPrimaryHomeServer
                objUser.put "msRTCSIP-UserEnabled", True

                'objUser3.put "msRTCSIP-TargetHomeServer"
                'objUser3.put "msRTCSIP-OriginatorSid"
                'objUser3.put "msRTCSIP-LineServer"
                'objUser3.put "msRTCSIP-UserExtension"

And off course don't forget the: objUser.setinfo at the end

Posted by Benjamin-Pierre | with no comments
Filed under: , , ,

[BATCH] - Get modified date with FOR /F

I had to write a batch script for a client, to automate a proccess.

I was required to check the modification date of a file and compare it to the current date...
This seemed quite easy, but took me some time as the date would not let me to "trim" her...

Now here is the working code I wrote for it


@echo OFF
SETLOCAL EnableDelayedExpansion

set directory="C:\The_Directory_you_whish_to_check"
set file=%%a
set size=%%~Za
set mydate=%date%
set lastmod=%%~Ta



for /f "tokens=* delims=" %%a in ('dir /b "%directory%*.txt"') do (

echo %lastmod% > %directory%Autoreport\temp.txt
set /p var=<%directory%Autoreport\temp.txt
set myvar=!var:~0,10!
echo !myvar!
)

ENDLOCAL


Strange that I had to export the parameter to an textfile and reimport it to make it work.
But I guess, ends good all good

Posted by Benjamin-Pierre | with no comments
Filed under: , ,

[VBS] MOVE EMPTY FOLDERS

It's very annoying to have a lot of empty folders hanging around....


I've written a smal VBS script to check one location (user input) for empty folders.

If it finds empty folders it will move them to C:\EMPTYFOLDERS (you can edit the destination in the code.)


Here is the full code:


On Error Resume Next

   rootfolder = Inputbox("Enter directory/foldername: " & _
                         chr(10) & chr(10) & "(i.e. C:\Program Files or " & _
                         "\\Servername\C$\Folder)" & chr(10) & chr(10), _
                         "Getfoldersize", "C:\Folder")

   Set fso = CreateObject("scripting.filesystemobject")


'Run checkfolder

If (FSO.FolderExists(rootfolder)) Then
   CheckFolder (FSO.getfolder(rootfolder))
End If

Sub CheckFolder(objCurrentFolder)

If (FSO.FolderExists(objCurrentFolder)) Then
    
 For Each objFolder In objCurrentFolder.SubFolders

If (FSO.FolderExists(objFolder)) Then

FolderEmpty(objFolder)



End If
 Next
End If

End Sub


Function FolderEmpty(path)
WScript.Echo(Path)
    ' Check for an empty folder.
    Dim fso, oFolder, oFiles         ' Object variables
    Dim i, flag

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set oFolder = fso.GetFolder(path)   ' Get folder.
    Set colSubfolders = oFolder.Subfolders
    Set oFiles = oFolder.Files          ' Get Files collection.

    flag = True                         ' No files
    For Each i in oFiles                ' A file has been found if
        flag = false                    ' the loop is processed.
        Exit For
    Next

    For Each objSubfolder in colSubfolders        ' No Subfolder
         flag = false                    ' the loop is processed.
            Exit For
    Next

    FolderEmpty = flag                  ' Return result.

If (FolderEmpty = "True" and Path<>"C:\EMPTYFOLDERS") Then
WScript.Echo(FolderEmpty)

fso.MoveFolder oFolder,"C:\EMPTYFOLDERS\"&oFolder.Name

End If

End Function


Enjoy

Posted by Benjamin-Pierre | with no comments
Filed under: ,