18 July 2013

Different colors on the same line

In order to have different font colors or different background colors in your console output you can use Write-Host cmdlet with the -NoNewline parameter:


Write-Host '1' -ForegroundColor Red -NoNewline
Write-Host '2' -ForegroundColor Green -NoNewline
Write-Host '3' -ForegroundColor Yellow -NoNewline


will output:

123

08 July 2013

Hide user from GAL / Global Address List



Set-Mailbox -HiddenFromAddressListsEnabled $true -Identity $user.UserPrincipalName

04 July 2013

Full error Exception details

If you need full error name for your catch cmdlet or any other reason the only way to obtain it is by piping  the $Error automatic varialbe to one of the Format cmdlet and use the -Force parameter.
The Exception property of the $Error variable will contain the information:

$Error[0] | Format-Table * -Force

Exception  : Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException:  Cannot find an object with identity: 'kajdhlkasd' under: 'DC=home,DC=net'.