Saturday, December 8, 2007

Sunday, December 2, 2007

Perform an AD Search Using Alternate Credentials

Perform a Search Using Alternate Credentials


Microsoft Windows XP - Create a shortcut using runas command parameters

'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 2007
'
' NAME:
'
' AUTHOR: mike mccafferty , mmcc
' DATE : 12/2/2007
'
' COMMENT: sites of interest
' http://www.windowsitlibrary.com/Content/2026/08/2.html
' using runAs with a shortcut
' http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/windows_security_runas_shortcut.mspx?mfr=true
' ADU&C runas /user:DomainName\administrator "mmc %windir%\system32\dsa.msc"
' ADU&C runas /netonly /user:DomainName\UserName "mmc.exe dsa.msc"
'




'==========================================================================
Sub WMIalternateCreds1()

' From the book "Windows XP Cookbook"
' ISBN: 0596007256

' Note that you cannot use this to connect to the local machine.
' ------ SCRIPT CONFIGURATION ------
strServer = "" ' e.g. wks01
strUser = "" ' e.g. AMER\rallen.adm
strPasswd = ""
' ------ END CONFIGURATION ---------
on error resume next
set objLocator = CreateObject("WbemScripting.SWbemLocator")
set objWMI = objLocator.ConnectServer(strServer, "root\cimv2", _
strUser, strPasswd)
if Err.Number <> 0 then
WScript.Echo "Authentication failed: " & Err.Description
end if

' Now you can use the objWMI object to get an instance of a class
' or perform a WQL query. Here is an example:
colDisks = objWMI.InstancesOf("Win32_LogicalDisk")


End Sub


Sub ADalternateCreds2()
Dim objConn
Set objConn = CreateObject("ADODB.Connection")
objConn.ConnectionString = "Provider=ADSDSOObject;" & _
"User ID=MyUserID;Password=MyPassword;"
objConn.Open

End Sub

Sub ADalternateCreds3()

' You get a choice, you can either
' hard-code the Domain Name (or a Domain Controller Name) only,
' then get the Distinguished Name from Root DSE:
'



Const DOMAIN_NAME = ""

Set objLDAP = GetObject("LDAP:")
Set objRootDSE = objLDAP.OpenDSObject("LDAP://" & DOMAIN_NAME &_
"/RootDSE", strUsername, strPassword)


'Or Hardcode both, and just connect directly to the target container:


Const DOMAIN_NAME = ""
Const CONTAINER_PATH = "OU=SomeOU,DC=SomeDomain,DC=local"

Set objLDAP = GetObject("LDAP:")
Set objRootDSE = objLDAP.OpenDSObject("LDAP://" & DOMAIN_NAME &_
"/" & CONTAINER_PATH, strUsername, strPassword)


' You would have to specify a value for strUsername and strPassword in all cases.
'
' Personally, I favour pulling the Distinguished Name from RootDSE rather than hard-coding it. It just makes things easier to maintain for me.
'
' Chris

End Sub


Sub ADalternateCreds1()
On Error Resume Next

Const ADS_SCOPE_SUBTREE = 2

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Properties("User ID") = "Administrator"
objConnection.Properties("Password") = "+77m5trgJo!"
objConnection.Properties("Encrypt Password") = TRUE
objConnection.Properties("ADSI Flag") = 1
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

objCommand.CommandText = _
"SELECT Name FROM 'LDAP://dc=fabrikam,dc=com' WHERE objectCategory='user'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

Do Until objRecordSet.EOF
Wscript.Echo objRecordSet.Fields("Name").Value
objRecordSet.MoveNext
Loop

end sub

Log Parser 2.2

WindowsDevCenter.com -- Using Log Parser 2.2
Log Parser 2.2 and ASP.NET
TechNet Webcast: Efficient Data Mining with Log Parser 2.2 (Level 300)
Microsoft TechNet column Tales from the Script - January 2005 All You Need is Log (Well, Log Parser)
Finding Duplicate Names in Active Directory - blog.scottlowe.org - The weblog of a senior engineer specializing in virtualization, storage, and servers
Complex Queries Against Active Directory - blog.scottlowe.org - The weblog of a senior engineer specializing in virtualization, storage, and servers

Saturday, December 1, 2007

free tools

Carl J » 15+ Free Visual Studio Add-Ins
Carl J » 15+ FREE Visual Studio Add-ins - Part 2
Carl J » 21+ FREE Regular Expression Tools & Resources (for .Net Developers)

regularExpressions 2

regex101
Regular Expression Visualizers for VS 2005

parse-textObject – AWK with a vengeance.

Carl J » 21+ FREE Regular Expression Tools & Resources (for .Net Developers)

For those starting out with Regex'es or those who are old hands here are some resources to help.
.NET Framework Developer's Guide .NET Framework Regular Expressions
Character Classes such as . \d \s [ ] defined.
Quantifiers such as + * ? { }
Options such as Multiline Compiled SingleLine
.Net Classes such as Regex Match MatchCollection GroupCollection
Examples
Tutorials
30 Minute Regex Tutorial on CodeProject.
.Net Coders Regex Overview breaks down groups and matches in one of the best overviews of the topics.
Introduction to Regular Expressions on CodeProject.
Understanding Basic Regular Expression Syntax (Section 3.10.) in the CodeProject's book chapter preview Microsoft Visual C# .NET 2003 Developer's Cookbook. Its a preview of Chapter 3: Strings and Regular Expressions.
Eric Gunnerson's Regex 101. A listing of differing match topics. Great for a beginner to look at after acquiring the basics of Regex, many examples.
How to: Search Strings Using Regular Expressions (C# Programming Guide) in MSDN Library.
Topics
Regular Expressions and the If Conditional on OmegaCoder's blog.
Want faster regular expressions? Maybe you should think about that IgnoreCase option...
(Compilation) For an overview of the three different modes, interpreted, on-the-fly compiled and precompiled see the MSDN article CLR Inside Out, "Base Class Library Performance Tips and Tricks"
(Compilation To an Assembly) section 3.13. Building a Regular Expression Library in the CodeProject's book chapter preview Microsoft Visual C# .NET 2003 Developer's Cookbook. Its a preview of Chapter 3: Strings and Regular Expressions.
Regex and Balanced Matching by Ryan Byington (MSFT) see als How to use RegexOptions IgnorePatternWhitspace from the Base Class Library (BCL) Team Blog.
A look into Matching Balanced Constructs with .NET Regular Expressions by Wes Haggard.
Regex Hangs My Expression by David Gutierrez in the BCL team blog.
The RegexOptions.Compiled Flag and Slow Performance on 64-Bit .NET Framework 2.0 BCL Team Blog
Programs (Not Sponsored or Endorsed by Microsoft) Just listed; no order implied.
Regular Expression Designer (.Net 1)
Expresso (.Net 2)(Free but registration) Used by most regex'ers; tool updated in 2007 to version 3.
RegEx Buddy ($)
Regular Expression WorkBench (.Net 1.1)(Free)
Regular Expression Visualizer for VS2005 by Roy Osherove. Write up about it here at Visual Studio Hacks. Its a VS2005 add-in.
Regulator also by Osherove, which is a stand alone regex tester.
Web Based Regex Testers
.Net Coders Expression Tester
Regex Testor by RegExLib.com main site has library of regex'es for browsing.
Other Non Regex Tools
GPLEX Lexical Analyzer for when Regex comes up short and a forum post that gives an example of its usage.
Forums
RegexAdvice.com is where the core regexer's, many different languages not just .net, give advice. Let them know you are using the .Net version.
Google Groups Regex Discussing Regular Expressions in variuos tools (perl, php, egrep, PowerGREP, .NET, procmail etc. etc). Let's help each other build effective regexes!
ASP Message Board : Regular expressions general discussions.
Books
Regular Expressions with .NET (ebook) by Dan Appleman.
Mastering Regular Expressions by Jeffrey Friedl.
Sams Teach Yourself Regular Expressions in 10 Minutes by Ben Forta.
Regular Expression Recipes: A Problem-Solution Approach (ebook) by Nathan Good.

Active Directory (AD) Organizational Units,

InformIT Managing OUs, Users, and Groups in Active Directory Administering OUS
Scripts and Files of the Inside Active Directory book
Rem Managing GPO Links
TechTasks Code Center VBScript
Display OUs (VBScript) - Active Directory Cookbook, 2nd edition
VBScript OUs
Modify-the-General-Properties-of-an-OU