Posts Tagged ‘Tips’

Quicker copies with Robocopy . .

February 7, 2011 Leave a comment

So I was messing about with Robocopy over the weekend and I decided to re-run an old copy job, using a new Desktop.
Strangely, my copy did not kick off like it did before. The problem – the new version of robocopy has new features and new syntax (yes I know it has been out a while – thanks clever clogs . . . )

anyway, long story short, looking at the updated switches, I noticed :

/MT[:n] :: Do multi-threaded copies with n threads (default 8).
n must be at least 1 and not greater than 128.
This option is incompatible with the /IPG and /EFSRAW opt

How awesome is that! The new robocopy runs Multi threaded and can be ramped up to 128 Threads!!!!!!! (this is Vista onwards I believe. – seems something good actually did come with Vista?)

Categories: Scripting, Tech Tips, Toolbox Tags: , ,

Useful websites . . searching for Microsoft / Mac / Linux / BSD related results

February 1, 2011 Leave a comment

As a techie . . I heavily rely on google for answers to questions that relate to various IT systems (seeing as most people know more than me)

Well, the majority of my queries are related to Windows / Microsoft and supporting tools.

some of you may know this (and some of you may not), but Google has actually built a tool just for techies like us.

If you browse to you’ll be able to run a search that only queries websites that are specifically related to Microsoft support etc.

but this is not all . .there are a few others..

Apple Search for Mac & Apple things Search for the BSD operating systems Search for the Linux operating system Search Microsoft-related pages
U.S. Government and state Search .gov, .mil and state sites Narrow your search to a specific institution’s website

Definitely worth a look (methinks)

Categories: Toolbox Tags: , ,

‘The terminal server has exceeded the maximum number of allowed connections.’ when trying to remote connect to the server

January 26, 2011 Leave a comment

To query and list the sessions on the remote session, you could use QUser.exe or QWinsta, or Powershell.

Powershell is my usual weapon of choice . .

PSTerminalServices is a PowerShell module that helps you manage Terminal Services (including Remote Desktop connections) sessions and processes.

The module is based on an open source project named Cassia (version, a .NET library for accessing the native Windows Terminal Services API.

You’ll need to download the module from and then ‘Import’ the module

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.


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.

Some Code Examples

For more code examples use Get-Help <cmdletName> –Examples.

# Logs off all the active sessions from remote computer 'Labserv07', no confirmations.
PS> Get-TSSession -ComputerName Labserv07 -State Active | Stop-TSSession –Force
# Gets all Active sessions from remote computer 'Labserv07', made from IP addresses that starts with '10'.
PS> Get-TSSession -ComputerName Labserv07 -Filter {$_.ClientIPAddress -like '10*' -AND $_.ConnectionState -eq 'Active'}
# Displays a message box inside all active sessions of computer name 'Labserv07'.
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 Labserv07 | Send-TSMessage -Message $Message
#Gets all processes connected to session ID 0 from remote computer 'Labserv07'.
PS>Get-TSSession -Id 0 -ComputerName Labserv07 | Get-TSProcess

2. QUser

QUser command comes with all the latest Windows clients and servers. This will list the sessions of the remote server (or local machine).

NOTE: if you are using Windows XP, you need to add this location into your System path: C:\Windows\System32\DLLCache. To do this, in command prompt, type the following.

SET PATH = %PATH%;C:\Windows\System32\DLLCache;

QUser help shows,

C:\Anand>QUser /?
Display information about users logged on to the system.

QUERY USER [username | sessionname | sessionid] [/SERVER:servername]

username Identifies the username.
sessionname Identifies the session named sessionname.
sessionid Identifies the session with ID sessionid.
/SERVER:servername The server to be queried (default is current).


C:\>quser /server:LabServer1

LabAdmin           rdp-tcp#49          2  Active          .  26/01/2011 1

Logoff the user / session

Logoff command kicks off (logging off) the specified remote session. Log off help shows,

C:\>logoff /?
Terminates a session.

LOGOFF [sessionname | sessionid] [/SERVER:servername] [/V]

sessionname The name of the session.
sessionid The ID of the session.
/SERVER:servername Specifies the Terminal server containing the user
session to log off (default is current).
/V Displays information about the actions performed.


C:\>logoff /server:LabServer1  1 /v
Logging off session ID 1

3. QWinsta

QWinsta is little different and better. It has more features and options. It comes with all flavors of Windows. QWinsta command line help displays as,

C:\>qwinsta /?
Display information about Terminal Sessions.

QUERY SESSION [sessionname | username | sessionid]
[/SERVER:servername] [/MODE] [/FLOW] [/CONNECT] [/COUNTER]

sessionname Identifies the session named sessionname.
username Identifies the session with user username.
sessionid Identifies the session with ID sessionid.
/SERVER:servername The server to be queried (default is current).
/MODE Display current line settings.
/FLOW Display current flow control settings.
/CONNECT Display current connect settings.
/COUNTER Display current Terminal Services counters information.


C:\>qwinsta /server:LabServer1

SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE

console                                     0  Conn    wdcon

rdp-tcp                                 65536  Listen  rdpwd

rdp-tcp#2         admvanwyka                1  Active  rdpwd

RWinsta (Logoff the user sessions)

RWinsta has same parameters and does same thing as log off command. It simply means Reset WINdows STAtion. The help goes as,

C:\>RWinsta /?
Reset the session subsytem hardware and software to known initial values.

RESET SESSION {sessionname | sessionid} [/SERVER:servername] [/V]

sessionname Identifies the session with name sessionname.
sessionid Identifies the session with ID sessionid.
/SERVER:servername The server containing the session (default is current).
/V Display additional information.


C:\>RWinsta /Server:LabServer1 1

Note: RWinsta command does not return anything.

Remember – killing an active session will log off the user – so play nice!

There goes – three different command line methods for logging off sessions . . . (of course if you are the GUI type, you could just use The Terminal Services Session Manager)

Categories: Tech Tips Tags: , ,

Powershell – function to Query a SQL database

January 21, 2011 Leave a comment

# Today’s quick and easy function is a simple one that I regularly use to query a SQL database.

It will return an object containing the result of your query – so makes SQL access very simply from Powershell

Function QuickQuery-SQL {
## Performs a T-SQL query against an SQL 2000/2005/2008
## with the result returned as as a PowerShell object.
## QuickQuery-SQL "server" "database" "t-sql query"
## Find NodeID from FindIt DB
## $output = QuickQuery-SQL "MySqlServername" "MyDatabase" "SELECT * FROM MyTable WHERE name = 'MySearchValue'"
Param ($server = "MyServer\MyInstance",
$database = "master",
$query = "SELECT * FROM sysdatabases",
$connectionName = "PS QuickQuery SQL",
$commandTimeout = 15)
$conn = <strong>new-object</strong> ('System.Data.SqlClient.SqlConnection')
$connString = "Server=$server;Integrated Security=SSPI;Database=$database;Application Name=$connectionName"
$conn.ConnectionString = $connString
<strong>Write-Debug</strong> ("Function: Query-SQL: $server $database")
if (<strong>test-path</strong> variable:\conn) {
} else {
$conn = <strong>new-object</strong> ('System.Data.SqlClient.SqlConnection')
$sqlCmd = <strong>New-Object</strong> System.Data.SqlClient.SqlCommand
$sqlCmd.CommandTimeout = $CommandTimeout
$sqlCmd.CommandText = $query
$sqlCmd.Connection = $conn
$data = $sqlCmd.ExecuteReader()
while ($ -eq $true) {
$max = $data.FieldCount -1
$obj = <strong>New-Object</strong> Object
For ($i = 0; $i -le $max; $i++) {
$name = $data.GetName($i)
if ($name.length -eq 0) {
$name = "field$i"
$obj | <strong>Add-Member</strong> Noteproperty $name <em>-value</em> $data.GetValue($i) -Force
$conn = $null

Ever had 2 PCs with 2 Screens . . but did not fancy messing around with 2 keyboards and 2 mice?

January 20, 2011 Leave a comment

Sourceforge have written a cracking (and free) tool that will allow you to share one keyboard and mouse between multiple different computers.

Have a look at :

“Synergy lets you easily share a single mouse and keyboard between multiple computers with different operating systems, each with its own display, without special hardware. It’s intended for users with multiple computers on their desk since each system uses its own monitor(s).”

Officially, the following are supported (and you can run any mix of these together)

  • Microsoft Windows 95, Windows 98, Windows Me (the Windows 95 family)
  • Microsoft Windows NT, Windows 2000, Windows XP (the Windows NT family)
  • Mac OS X 10.2 or higher
  • Unix

but I have also managed to get it to work with Windows 7 (as long as the ‘server’ is hosted on the Windows 7 box)

what I particularly liked was the fact that I could copy and paste (both text and images) between desktops . . even when they are running different Operating systems.

Categories: Gadgets, Toolbox Tags: , , ,

Essential Tools . . FastSCP

January 20, 2011 Leave a comment

how many times have you had to move a VM from a Datastore on one ESX host to that on another.

Sure – storage migrate is an easy option  . . . if you

a) Have a vCenter

b) Are presenting both sets of storage to an ESX host

and/or c)  are licensed to the correct level.

the solution . . Veeam’s FastSCP.

simple – register at

Download . . connect to both ESX hosts . . and copy / move away like you’re a Windows GUI user (though of course you’re a geek . . .so you would have preferred to do it from the command line)

Happy Days..

you can add the ESX hosts, or your VC . . or even multiple VC is you have them (I use this to move vmdks between the lab and production . .

Once you’ve added your Virtual Centre(s) – you can simply browse the datastores and copy  files as if you were using Windows explorer.