Skip to main content

Posts

Showing posts from October, 2011

Removing sIDHistory attribute

When using PowerShell Commands for Active Directory modifications on AD objects are scripted easily. But dealing with some properties (e.g., sIDHistory) requires a special approach. Let's say we need to clear the sIDHistory for the account TEST01 This account does have the sIDHistory attribute populated [PS] C:\>$user=Get-QADUser -SamAccountName TEST01  -IncludedProperties sidhistory [PS] C:\>$user.sIDHistory 0105000000000005150000002B012212B316AD0EEE04CFAD576F1600 If we want to clear an attribute like DisplayName we can use Set-QADUser and set the attribute to $null like this: [PS] C:\>Set-QADUser $user -ObjectAttributes @{DisplayName=$null} Name                    Type            DN ----                    ----            -- Test01,User             user            CN=Test01, User... or that [PS] C:\>Set-QADUser $user -ObjectAttributes @{DIsplayName=@{delete=$user.DisplayName}} Name                    Type            DN ----            

How to Schedule an Script with Exchange cmdlets

when I need to schedule a PS script or to run a PS script from a command line I create a batch file containing the following two lines: @echo off powershell -psconsolefile "C:\Program Files\Microsoft\Exchange  Server\bin\Exshell.psc1" -Command "&{%~dpn0.PS1}" The %~dpn0.PS1 expression refers to a file with the same file name ( %~n0 ) as the batch file, located on the same drive ( %~d0 ) and in the folder ( %~p ) as the batch file.  And it correctly handles spaces in the folder name (because of double quotes). Thus, if you need to schedule a PS script named MyScript.PS1 you need to create a CMD file named Myscript.CMD and place it into the same folder where the PS1 script resides. And that's it.

Move Old Files to an Archive Folder

I have a folders structure where I store my scripts, backups, documents as shown below The folders becomes cluttered with old versions of the files. So I decided to create a script that will move old files from each of the folders beneath the root one (e.g., C:\WP) to an archive sub-folder (if it exists at the particular level). So I decided to archive old files in the Backups, Exchange, and SharePoint folders. I created sub-folders called 'ARCHIVE' under each of those three folders as shown below And then I created the following batch file @ECHO OFF SETLOCAL SET ArchiveFolder=Archive SET OlderThan=2 SET Extensions=TXT CSV BAK LOG REM starts from the current folder  REM   [when it's a scheduled task this is configured as "START IN"] REM CD C:\WP SET debug=ECHO  SET LogFile="%~dpn0.LOG" FOR /F %%m in ('CD') Do SET StartDir=%%m %debug%.>>%LogFile% %debug%.>>%LogFile% %debug%.>>%LogFile% %debug%