February 2010 - Posts
Have you ever read Help that wasn't really helpful? Here's your chance to fix it.
The Windows PowerShell Community Review process is looking for volunteers for the third documentation review cycle – especially beginners and intermediate PowerShell users and people with little or no programming background.
The Windows PowerShell documentation team and PowerShellCommunity.org jointly sponsor the Windows PowerShell Community Doc Review. As a member, you'll get to read and comment on the Help docs before they're published, and work with the writers, editors, and the product team to make sure every word is really helpful.
”We're looking for users at all experience levels and with all different backgrounds, but we love to have beginners, people with no programming experience, people who know other scripting languages or shells, and people who are not native English speakers. If you're a system admin and you don't really know Windows PowerShell, this is a great way to learn it with help from insiders.”
Ready to rock the help? Contact June Blender (juneb@microsoft.com) or Marco Shaw (marco.shaw@gmail.com).
PSTerminalServices is a PowerShell module that helps you manage Terminal Services (including Remote Desktop connections) sessions and processes. No more legacy applications text parsing!
The module is based on an open source project named Cassia (version 2.0.0.60), a .NET library for accessing the native Windows Terminal Services API.
What you can do with it
The following operations are supported on local and remote computers:
- Enumerating terminal sessions and reporting session information including connection state, user name, client name, client display details, client-reported IP address, and client build number.
- Logging off a session.
- Disconnecting a session.
- Displaying a message box in a session.
- Enumerating all processes or processes for a specified session.
- Killing a process.
Supported Platforms
Cassia has been tested on Windows Server 2008 R2 beta (RTM?), Windows Server 2008, Windows Server 2003, Windows XP, and Windows Server 2000. It should work on Windows Vista as well.
Cassia - Source Files
Cassia source files are included in the module's bin directory (compressed file).
Functions
The following functions are added to the current session when you import the module:
Disconnect-TSSession - Disconnects any attached user from the session.
Get-TSCurrentSession - Provides information about the session in which the current process is running.
Get-TSServers - Enumerates all terminal servers in a given domain.
Get-TSProcess - Gets a list of processes running in a specific session or in all sessions.
Get-TSSession - Lists the sessions on a given terminal server.
Send-TSMessage - Displays a message box in the specified session ID.
Stop-TSProcess - Terminates the process running in a specific session or in all sessions.
Stop-TSSession - Logs the session off, disconnecting any user that might be connected.
Getting help
All functions are decorated with comment-based help so you can use Get-Help against any of the functions just like you would do with any other cmdlet. The module also include a help topic file, about_PSTerminalServices_Module, which you can read by typing the following in your current session:
PS > Get-Help about_PSTerminalServices_Module
Some Code Examples
For more code examples use Get-Help <cmdletName> –Examples.
# Logs off all the active sessions from remote computer 'comp1', no confirmations.
PS> Get-TSSession -ComputerName comp1 -State Active | Stop-TSSession –Force
# Gets all Active sessions from remote computer 'comp1', made from IP addresses that starts with '10'.
PS> Get-TSSession -ComputerName comp1 -Filter {$_.ClientIPAddress -like '10*' -AND $_.ConnectionState -eq 'Active'}
# Displays a message box inside all active sessions of computer name 'comp1'.
PS>$Message = "Important`n, the server is going down for maintenance in 10 minutes. Please save your work and logoff."
PS> Get-TSSession -State Active -ComputerName comp1 | Send-TSMessage -Message $Message
#Gets all processes connected to session ID 0 from remote computer 'comp1'.
PS>Get-TSSession -Id 0 -ComputerName comp1 | Get-TSProcess
Bugs/Suggestions
Bugs related to Cassia can be reported directly to its mailing list: cassia-users@googlegroups.com. Module Bugs/Suggestions/Comments can be reported to the module Discussions page.
Updating an attribute value in Active directory is usually not a big deal. Most of the attributes are single valued and you can easily modify them. However, dealing with multi valued attributes is another game.
With Quest AD cmdlets you don’t have to pull your hair out, there is special syntax for working with multi valued attributes and you use it via the ObjectAttributes parameter. The syntax is as follows (nested hashtable):
Set-QADUser -Identity <Identity> -ObjectAttributes @{AttributeName=@{KeyName=@(‘value1’,’value2’…)}}
AttributeName – The LDAP name of the attribute.
KeyName - The action you want to perform on the attribute value(s). The values
@(‘value1’,’value2’…) – An array of values.
There are four key names we can use to modify multi value attributes:
Append - Adds one or more values to the attribute while preserving any existing entries.
Clear - Removes all values and set the attribute value to null.
Delete - Removes one or more values from the attribute while preserving any other existing entries.
Update - Removes any existing values and then writes one or more new values to the attribute.
Lets take the otherTelephone attribute as an example and get its content.
PS > Get-QADUser -Identity shay -IncludedProperties otherTelephone | Format-List otherTelephone
otherTelephone :
There are no values so let’s add two phone numbers. The ‘Append‘ key name is suitable for that action.
PS > Set-QADUser -Identity shay -ObjectAttributes @{otherTelephone=@{Append=@(‘111-111-1111’,’222-222-2222’)}}
PS > Get-QADUser -Identity shay -IncludedProperties otherTelephone | Format-List otherTelephone
otherTelephone : {111-111-1111, 222-222-2222}
Sometimes we will want to replace all values with new ones:
PS > Set-QADUser –Identity shay -ObjectAttributes @{otherTelephone=@{Update=@(‘333-333-3333’,’444-444-4444’)}}
PS > Get-QADUser –Identity shay -IncludedProperties otherTelephone | Format-List otherTelephone
otherTelephone : {333-333-3333, 444-444-4444}
Now let’s remove one of the numbers:
PS > Set-QADUser –Identity shay -ObjectAttributes @{otherTelephone=@{Delete=@(‘333-333-3333’)}}
PS > Get-QADUser –Identity shay -IncludedProperties otherTelephone | Format-List otherTelephone
otherTelephone : 444-444-444
Finally, to clear all values (set the attribute to null) use the Clear key without any values:
PS > Set-QADUser –Identity shay -ObjectAttributes @{otherTelephone=@{Clear=@()}}
PS > Get-QADUser –Identity shay -IncludedProperties otherTelephone | Format-List otherTelephone
otherTelephone :
The same technique can be used against any multi valued attribute, such as ProxyAddresses (modifying email addresses). How do you know which attributes are multivalued? You can get a list by searching the schema:
PS > Get-QADObject –SizeLimit 0 -LdapFilter "(isSingleValued=FALSE)" –SearchRoot (Get-QADRootDSE).SchemaNamingContext -Type attributeSchema -IncludedProperties LDAPDisplayName | Format-Table LDAPDisplayName