CODE – PowerShell get user object info

Get user object information for Active Directory

This code demonstrates how to search and retrieve User Object information from Active Directory without any plug-ins.
To run this script within your environment you should only need to copy and paste this script into either Windows Powershell ISE with the following changes to the script which I have numbered below.
Change the line, ($strUserName = “samAccountName”), so that you have a real User ID.
You can also search in a specific Active Directory OU By changing the second line of code
From: “$objDomain = New-Object System.DirectoryServices.DirectoryEntry”
To: “$objDomain = New-Object System.DirectoryServices.DirectoryEntry(“LDAP://OU=ASDF,DC=asdf,DC=asdf”)”

CODE – Powershell get-ad information

Get-AD

This Script retrieves information from Active-Directory. It’s got a few Parameters and Switches that allows us to specify what to search for and how to Return the objects found. You can choose which information to return through the Property parameter, you can Save the Information to a Csv file, You can return a System.DirectoryServices.DirectoryEntry Object that you can work with through PowerShell and alot more.

Parameters:

  • -Domain Name of the Domain (Required)
  • -OU Name of Organizational Unit (Optional)
  • -User Name of the User (Optional)
  • -Group Name of the Group (Optional)
  • -Computer Name of the Computer (Optional)
  • -Filter Filter on Specified Criteria, default is name (optional)
  • -CustomFilter Create A custom SearchFilter (optional)
  • -CustomAll Create A Custom SerachFilter, searches for All Objects (optional)
  • -Property Specify one or more Properties to Return (Optional)
  • -ToCsv Saves the Output to a Csv File (Optional)
  • -ToObject Returns a System.DirectoryServices.DirectoryEntry Object (optional)
  • -IncreasePageSize Exceeds the default limit of 1000 Objects (optional)
  • -help Prints the HelpFile (Optional)

Here are a few Example Scenarios on running The Script

You want to display a HelpText about the Script

You want to Display Domain Information About Your Domain

You want to Connect to a Domain and store the Object in a Variable

You want to retrieve All OrganizationalUnits in your Domain and store their distiguishedName in a Csv file

You want to Get all Users and display their name and mail in your PowerShell Session

You want to Find a User, but you only know the Users sAMAccountName

 

You want to Create a Csv File with all Computers in your domain

HOW-TO Enable PowerShell scripts on windows

By default, PowerShell has scripting support disabled. If you try and run a PowerShell script, you will be greeted with an error stating that the execution of scripts is disabled on your system. To enable scripting support so that your scripts will run, read on:

1. Open PowerShell (if you are running PowerShell on Windows Vista, right-click your PowerShell icon and select Run as administrator. If you don’t do this, you will not be able to enable script support).

2. Check the current script execution policy by using the Get-ExecutionPolicy cmdlet. To do this, input Get-ExecutionPolicy and press Enter on your keyboard. PowerShell will return a value of Restricted.

3. To change the script execution policy, use the Set-ExecutionPolicy cmdlet. Input Set-ExecutionPolicy unrestricted and press Enter on your keyboard.

4. To ensure that the script execution policy has been changed, use the Get-ExecutionPolicy cmdlet again. PowerShell should return a value of Unrestricted.

You can now run your PowerShell scripts.

CODE – VB delete all profiles

Language: Visual Basic Script
Note: DeleteProfiles.vbs

CODE – Javascript Function format as currency

Simple Format as currency in American dollars $. formatCurrency(number) you can modify the regExpression to make this work for other currencty formats.

CODE – Powershell remove a profile from a RDS session host.

CODE – Powershell send an email

Simple Powershell Script

 

Advanced Powershell Script

 

CODE – Javascript how to spell check a live website.

Requirements: FireFox

If you maintain a website, you will surely know how important it is to never have any spelling errors in your copy. And if you really care you will always run for sure a spell checker on all your text, but isn’t that quite over work? Wouldn’t it be much simpler if your browser did all the spell checking without you having to worry about anything?

Well, there is a very simple way of doing so, simply copy the following javascript code and paste it into the address bar: