It
is best practice to add the folder(s) that contain the custom cmdlets
and scripts to the system path. This allows the administrator to run
any one of the cmdlets from anywhere in the EMS console.
Cmdlets with the .ps1 extension cannot be run directly from the Cmd.exe console; they must be run within the Exchange Management Shell. Administrators can run cmdlets from the Cmd.exe console by calling EMS and the cmdlet. For example,
C:\>powershell mycmdlet.ps1
invokes EMS because powershell.exe is in the path, runs the mycmdlet.ps1 cmdlet, and exits back to the Cmd console.
The
cmdlets that ship with Exchange Server 2007 and EMS cannot be modified.
They have been optimized and compiled for maximum performance. These
native cmdlets are contained in the DLL files in the %SystemDrive%\Program Files\Microsoft\Exchange Server\bin folder.
It is a best practice to create a folder to contain the custom .ps1 files and add that folder to the system path. This facilitates the use of the .ps1 files within the EMS command line.
Developing a Common Naming Scheme
When
developing custom cmdlets, it is important to use functional names that
denote the use of the cmdlet. It is a best practice to use the same
verb-noun naming that is common in PowerShell and EMS. This provides
consistency in the management environment.
A cmdlet to send SMTP email from the EMS command line might be called send-email.ps1, for example.
Distributing Cmdlets
Cmdlets can be distributed in a number of ways, similar to VBScripts or batch files. Because .ps1 files cannot be executed from the Cmd.exe
shell, they can be sent using Outlook without the security restrictions
of executable code. Cmdlets can be emailed as attachments or their
contents can be pasted into the body of a message.
The
Microsoft distributed file system (DFS) offers another way to
distribute cmdlets. By creating replicas in remote sites, the
organization’s cmdlet library can be fault tolerant and available
locally to all administrators.
Another
option for distributing cmdlets is via SharePoint. SharePoint’s
document management features allow administrators to check in and check
out cmdlets as .ps1.ps1
files simple and provides full-text search capabilites. It also
provides security so that only the appropriate administrators have
access to certain cmdlets. files. This makes managing
Enabling Logging in EMS
Logging
can be enabled in the Exchange Management Shell. This is a great
feature for Exchange administrators as every command executed in either
the Exchange Management Console GUI or executed from the cmdline can be
logged. Logging is not enabled by default; however, it is a function
that can be enabled by configuration.