Search This Blog

Get-ADUser

Get-ADUser can get one or more Active Directory users; it’s part of Active Directory Module for Windows PowerShell.  It’s similar to Get-QADUser in Quest’s ActiveRoles Management Shell (However, ActiveRoles Management Shell can be installed on the older operating system)

Active Directory Module for Windows PowerShell is part of the Remote Server Administration Tools (RSAT) feature on a Windows Server 2008 R2 server; and it’s part of the RSAT feature on a Windows 7 computer (download).  However, it’s not available to install on any older operating system, including Windows Server 2008.

Basic usage of Get-ADUser

  • Get-ADUser –Filter { } or Get-ADUser –Filter *
  • Get-ADUser –Filter { } –SearchBase “DC=xxx,DC=com”
  • Get-ADUser –Filter { } –Properties * | Get-Member   # to get all the properties; be aware of the property name is different than Get-QADUser cmdlet.
  • Get-ADUser –Filter {} –Properties <propertyname1,propertyname2>  # to get the non-default properties to the pipeline

Exchange Server 2003 Public Folder Mail Enable or Disable Option

In Microsoft Exchange Server 5.5, all public folders were mail-enabled and hidden by default. In Exchange 2000 Server and Exchange Server 2003, folders can be mail-enabled or mail-disabled, depending on whether the Exchange Server organization is in mixed mode or in native mode.

If Exchange Server 2003 is in mixed mode, the Mail Disable is not available when right-click a public folder / All Tasks in Exchange System Manager, only the Mail Enable option is available (even the public folder is already mail enabled).

To access the Mail Disable option, change Exchange Server 2003 to native mode.

Reference:

PowerShell Credential Input

$cred = Get-Credential

will prompt the user entering the credential that can be used in other PowerShell script.

image

Or $cred = Get-Credential –Credential domain_name\user_name

to fill in the default user name.

image

Use $WhatIfPreference in PowerShell to Prevent Accidents

  • The default value of $WhatIfPreference variable is $false.
  • Adding “$WhatIfPreference = $true” to a script or the PowerShell profile
  • Now every cmdlet that supports a whatif switch will execute as the whatif switch is on
  • To overwrite the setting in a particular cmdlet, add –whatif:false in the cmdlet

PowerShell ExecutionPolicy Bypass

Windows PowerShell v.2 supports a bypass execution policy.  It can be used to overwrite the computer execution policy setting in batch script.

image

The computer execution policy is restricted.  A PowerShell script can not be executed.

image

With the bypass option, the script is able to execute.

PowerShell: Avoid Bank Lines at End of a Text File

Use System.IO.File .NET Framework class’s Write AllText static method.

[System.IO.File]::WriteAllText(string path, string contents)

or [System.IO.File]::WriteAllText(string path, string contents, System.Text.Encoding encoding)

e.g. [system.io.file]::WriteAllText(“c:\fso\ioascii.txt”, $count, [System.Text.Encoding]::ascii)

More info: [system.io.file] | get-member –static WriteAllText | fl *

[system.text.encoding] | get-member –static –MemberType property

Reference: http://blogs.technet.com/b/heyscriptingguy/archive/2011/09/19/avoid-blank-lines-at-end-of-a-text-file-with-powershell.aspx

Best Practices for DNS Client Setting in Windows Server Domain Controller with DNS Installed

Assume at least two domain controllers with DNS installed in the domain.

  • Configure the remote DNS server set as Preferred DNS server
  • Configure 127.0.0.1 as Alternate DNS server

Reference:

Use WinSCP to Transfer Files in vCSA 6.7

This is a quick update on my previous post “ Use WinSCP to Transfer Files in vCSA 6.5 ”. When I try the same SFTP server setting in vCSA 6.7...