Friday, August 15, 2008

PowerShell Support in SQL 2008

Was browsing the new features of SQL 2008. There are quite a lot and some interesting ones as well. One is the support of PowerShell. There are both a PS provider ("The provider lets you navigate the hierarchy of SQL Server objects using a path similar to a file system path. Each object is associated with a class from the SQL Server Management object models. You can use the methods and properties of the class to perform work on the objects. For example, if you cd to a databases object in a path, you can use the methods and properties of the Microsoft.SqlServer.Managment.SMO.Database class to manage the database.") and the ability to execute PowerShell commands from within the management application ("The SQL Server 2008 version of SQL Server Management Studio supports starting PowerShell sessions from the Object Explorer tree. The SQL Server 2008 version of SQL Server Agent supports PowerShell job steps"). Read it all here.

Thursday, July 17, 2008

Determining your Hyper-V version

<rant>

Figuring out versions is often way too hard. Why can't I simply see the version in Add or Remove Programs or in the feature overview? Why do I have to mess around with build numbers? Isn't this 2008!

</rant>

The other day, I had to figure out which Hyper-V and SCVMM version a server was running. Luckily, I found this and this article.

I PowerShelled the Hyper-V part, so you can use it easily in your scripts (and if you execute the WMIC command from PowerShell, it will not work owing to parsing differences between cmd and PowerShell). Here is my Get-HyperVVersion.ps1, but you can also execute it directly -

$file=get-command c:\windows\system32\vmms.exe
switch ($file.fileversioninfo.productversion.split(".")[-1]) {
17101 { "Beta" }
18004 { "RC0" }
18010 { "RC1" }
18016 { "RTM" }
}


Note how Get-Command can 'reveal' the versioninfo of a executable/DLL.

Tuesday, July 08, 2008

Get-PublicIp4Address.ps1

Using dyndns' checkip page and two lines of PowerShell, you can get your public IP address easily -

$wc=New-Object net.webclient
$wc.downloadstring("http://checkip.dyndns.com") -replace "[^\d\.]"



Note the use of -replace with a single argument. This removes the pattern and works like -replace "string","". I also really like that you can call a method and work directly on the output.



You could turn this into a one-liner -




(New-Object net.webclient).downloadstring("http://checkip.dyndns.com") -replace "[^\d\.]"



but I think the two-line version is much easier to read, so I'll stick to that.



PS. Regex interpreration: Remove everything not (^) a digit (\d) or a dot (\.). The webpage returns a string like "Current IP Address: 10.1.2.3" and I wanted to get rid of the extra stuff.

Monday, July 07, 2008

Microsoft Office Open Protocol Specifications

So Microsoft is releasing a lot of information on the way that it uses and support the different protocols in Office, which includes Office Communications Server 2007.

Why is this interesting for you/us? Well maybe you have a problem with ABS download, Firewall Traversal, Sending DTMF digits or similar issues that you have problems solving or maybe you are developing applications that integrate with the Microsoft UC platform; then these specifications are a excellent guide to the inner workings of OCS. Find information from the homepage here -

Microsoft Office Protocol Documents

The Microsoft Office protocol documentation provides detailed technical specifications for Microsoft proprietary protocols (including extensions to industry-standard or other published protocols) that are implemented and used by Microsoft Office 2007 to interoperate or communicate with other Microsoft products.

The documentation includes a set of companion overview and reference documents that supplement the technical specifications with conceptual background, overviews of inter-protocol relationships and interactions, and technical reference information.

Audience

The Microsoft Office protocol documentation is intended for use in conjunction with publicly available standard specifications and network programming art. It assumes that the reader either is familiar with this material or has immediate access to it.

The technical documentation provides the following levels of audience support:

  • Implementer: Sufficient conceptual and reference information for a successful implementation of one or more protocol specifications for a given task or scenario.

  • Reviewer: A definitive resource for readers who want to evaluate or understand one or more protocols.

The Microsoft Office protocol documentation provides detailed technical specifications for Microsoft proprietary protocols (including extensions to industry-standard or other published protocols) that are implemented and used by Microsoft Office 2007 to interoperate or communicate with other Microsoft products.

The documentation includes a set of companion overview and reference documents that supplement the technical specifications with conceptual background, overviews of inter-protocol relationships and interactions, and technical reference information.

Find the documentation at MSDN

Friday, July 04, 2008

Constructing commands/command line - a PowerShell hint

I was just trying to compose a correct robocopy command in my script - and instead of having robocopy to give me an error, I would like to see the command before attempting to test the command. Naturally, I could built up the command in a string and echo/execute that, but when it can be done easier (we are talking a 5 line script here) it should.

I have something like this

robocopy $from "$(split-path -parent $myinvocation.mycommand.definition)"\subpath /mir



Now, if I want to see what that resolves to, I normally would surround it with quotes, echoing it out. But when you do that, you have to take the existing quotes into account and start duplicating or escaping them. Not so great. And using single quotes is not an option as that will turn off variable substitution. Luckily, PowerShell has the here-double quote operator: @" "@. This multi-line quoting operator does not require quotes in the content to be doubled.



So to see the command, surround it with @" on the line above and place "@ on the line below. Remember that "@ must start in column 1 of the line to end the string.




@"
robocopy $from "
$(split-path -parent $myinvocation.mycommand.definition)"\subpath /mir
"
@



 



You should also remember that PowerShell has the here-single quote operator @' and '@. In this case, variable substitution is not performed.

Wednesday, July 02, 2008

Hyper-V SuperSite Article

Paul Thurrott has written/updated his Windows Server 2008 Hyper-V article. Amongst other things, it seems like Hyper-V performance is very good. Read it for yourself - worth a read!

Friday, June 27, 2008

Hyper-V RTM'ed

yesterday. So now I'll start updating my test system to see if these errors are gone:

  • Keyboard does not always work after a boot. A shutdown/start normally fixes the problem
  • Network is sometimes messed completely up if you switch the network the guest is connected to
  • "Type clipboard text" only works if you guest runs US English keyboard layout. It seems to generate/emulate keyboard stokes so slash are written as dashes (on a Danish keyboard)
  • Virtual Machine Connection crashes

Get the 64-bit update here. Remember to get rid of all save states and snapshots before upgrading! Get the full release notes here.

Tuesday, June 24, 2008

The WOW6432Node effect

Last night I was playing around with "Adding Commands to the Communicator Menus" and before I got it running I ran into an obstacle . Basically I wanted it to add extra menu entries in the Communicator menus.

The way to do this is by adding a following registry entry

HKEY_LOCAL_MACHINE\Software\Microsoft\Communicator\SessionManager\Apps\[GUID of Application]

and some keys

Name (Type:REG_SZ) to specify menu caption
ApplicationType (Type:DWORD), value can be either 0 (if application is executable) or 1 (if application is protocol)
Path (Type:REG_SZ) to specify full path to the executable
SessionType (Type: DWORD), value can be 0 (for local session), 1 (this is default for two party session) or 2 (for multi-party session)
ExtensibleMenu (Type:REG_SZ), value can be MainWindowActions, MainWindowRightClick (this is default value), ConversationWindowActions, ConversationWindowContextual (this is the default value) and ConversationWindowRightClick. Multiple values can be specified separated by semi-colons

So I started up a registry editor and added the above mentioned keys and launched my Office Communicator. But the "Contoso Sales C..." entry was missing. I did spend some time checking up on typos but came no where. So I decided to make use of Process Monitor to look for what kind of registry activities Office Communicator was having. Surprisingly the activities were only in this part of the registry HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Communicator. Just for the fun I moved my registry entry to this location and the entry in the Office Communicator worked like a charm.

The explanation for this I found on Windows IT Pro: "The Wow6432 registry entry indicates that you're running a 64-bit version of Windows. The OS uses this key to present a separate view of HKEY_LOCAL_MACHINE\SOFTWARE for 32-bit applications that run on a 64-bit version of Windows."

If you want to read more about customizing your Office Communicator the following links can useful for you.

Integrating a Third-Party Collaboration Program with Communicator 2007

Adding Commands to the Communicator Menus

How do ISA figure out which authentication to use?

So you have published your Exchange server and your are using forms based authentication (FBA). But when you use Outlook Anywhere or ActiveSync (MSRPC), it bypasses FBA. Why does it do that and how does that work?

Well, thanks to my coworker Claus-Ole Olsen, I got the question answered. ISA uses the User-Agent header/string to decide whether it will actually use FBA or not! You can also select different forms based on the value - for different device capabilities.

The ISA GUI tells you it uses FBA, but you just cannot trust that as the User-Agent header will modify the rule!

Read it all here on TechNet Microsoft Internet Security and Acceleration Server 2006 Managing User-Agent Mappings, including scripts for viewing and setting the values.

If you want to avoid the VBScript, you can use PowerShell. This is Get-IsaUserAgentMapping.ps1 -

 

param([switch]$pretty)
$root=new-object -com fpc.root
$isaArray=$root.GetContainingArray()
$mappings=$isaarray.ruleelements.UserAgentMappings |
select PersistentName,UserAgent,Description,Enabled,@{n="FBAFormsType";e={
# For values, see http://technet.microsoft.com/en-us/library/bb794715.aspx
switch ($_.FBAFormsType) { 0 {"HTML 4.01"} 1 {"cHTML"} 2 {"XHTML-MP"} 3 {"Basic"} }
}},order
if ($pretty.isPresent) {
$mappings | Sort Order | Format-Table -auto UserAgent,Description,Enabled,FBAFormsType,Order
}
else {
$mappings
}

 


Adding and modifying is left as an exercise for yourself ;)

Saturday, June 21, 2008

The first steps of programming Office Communicator

Hi there.

The last three weeks has been very exciting and the future is going to bring even greater things. You will probably ask you self why I would write this and to answer this I will use a few lines to explain.

My name is Peter and for the last few years been working in the telecommunication business. A month ago I was lucky enough to get employed by Inceptio to do consulting and development on the UC platform (E.g. OCS and Exchange).

For some time I have being reading and fooling around with the Office Communicator 2007 API SDK and it has been fun and at times frustrating. The reason for this post is to share ideas and possibilities provided by Microsoft UC platform. So to start from the beginning I thought of bringing a small and simple example and I will then continue to post more advanced samples based upon my own experiences with UC development. Below is my first example that shows how to hookup to some of the events that the Office Communicator 2007 Client exposes. Basically it writes a message in the console every time a new conversation windows starts or closes.

The example down below can be the foundation for an application that helps in retrieving information about the incoming caller. Information like calling history, email conversations, location information, billing information, project information. As one se the possibilities is endless.

In my next blog entry I will start to add functionality to retrieve some of the above mentioned information types.

Until then... 

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace EventFun
{
class EventHookUp
{
CommunicatorAPI.Messenger mCommunicator = null;
static void Main(string[] args)
{
EventHookUp hu = new EventHookUp();
hu.InitializeEventHocks();
Console.ReadKey();
}
public void InitializeEventHocks()
{
mCommunicator = new CommunicatorAPI.Messenger();
mCommunicator.OnIMWindowCreated += new CommunicatorAPI.DMessengerEvents_OnIMWindowCreatedEventHandler(mCommunicator_OnIMWindowCreated);
mCommunicator.OnIMWindowDestroyed += new CommunicatorAPI.DMessengerEvents_OnIMWindowDestroyedEventHandler(mCommunicator_OnIMWindowDestroyed);
}
void mCommunicator_OnIMWindowCreated(object pIMWindow)
{
CommunicatorAPI.IMessengerConversationWndAdvanced stpIMWindow = pIMWindow as CommunicatorAPI.IMessengerConversationWndAdvanced;
long Hwnd = (long)stpIMWindow.HWND;
Console.WriteLine("New IM Window Created : {0}", Hwnd);

//Listing Frindly name of the caller.
CommunicatorAPI.IMessengerContacts contactList = (CommunicatorAPI.IMessengerContacts)stpIMWindow.Contacts;
StringBuilder sb = new StringBuilder();
foreach (CommunicatorAPI.IMessengerContact imc in contactList)
{
sb.Append(imc.FriendlyName);
sb.Append(Environment.NewLine);
}
Console.WriteLine(sb.ToString());
}
void mCommunicator_OnIMWindowDestroyed(object pIMWindow)
{
Console.WriteLine("IM Window Destroyed.");
}
}
}



If you want to read more about the API’s then take a look at these posts/blogs



Chris Mayo -> http://blogs.msdn.com/cmayo/



Michael Dunn -> http://blogs.msdn.com/midunn/



George Durzi -> http://blogs.claritycon.com/blogs/george_durzi/default.aspx

Wednesday, June 11, 2008

Live Meeting update and GPO administrative template

Just a quick update - Microsoft has released a GPO Administrative template for Live Meeting that removes the dreaded "Test connection" dialog that end-users somehow do not fully appreciate ;-)

Find the description in KB article 948741 here and the accompanying updates for Live Meeting and the Outlook add-in that updates the clients to version 8.0.6362.70.

Original source LCSKid

Creating More Efficient Microsoft Active Directory-Enabled Applications

I just found this MSDN article about optimizing your queries. Besides good advice on how to create optimal queries, you can also instruct Active Directory to log expensive queries and even control the threshold value of when a query is expensive!

Furthermore, the ANR search is explained e.g. how you can search for 'Sam' when you do not know whether it is a name, a SAM account name etc. Just like the GUI search in Users and Computers.

 

And while you are at it, I can also recommend reading How Active Directory Searches Work.

Windows Home Server Evaluation Kit

Before getting a real kit, I would like to test it first. But so far I have not been able to find it for download anywhere. The officiel free trial page only allows you to order the kit on a DVD - not download.

Today, I found the evaluation download on connect and even better an evaluation version of Windows Home Server Power Pack 1. Power Pack seems to be Home Server'ish for  Service Pack and some new features. You can get a prerelease version of the release notes from connect.

As soon as the download finishes, I will load it up in Hyper-V :)

Thursday, June 05, 2008

winmgmt as a command line tool

The other day, I could not install AVG8 on someone's PC. Everything worked fine, but it could not register with Security Center. It turned out to be a WMI problem. I solved the problem with winmgmt and the /verifyrepository and /salvagerepository switches.

Read all the documentation about the command line switches  here at MSDN.

Thursday, May 22, 2008

Invoke-Vbscript - now supporting Vista x64

As mentioned in Is this PowerShell Session a 32-bit or a 64-bit?, Invoke-Vbscript was the reason I ventured out into that.

 

Here is the updated Invoke-Vbscript. It checks the architecture using Get-Architecture from Is this PowerShell Session a 32-bit or a 64-bit?. If it is 64-bit, it invokes the 32-bit powershell to run the script using a method described in Invoking PowerShell with complex expressions using Scriptblocks.

The script -

param($vbCode,[switch]$ExecuteStatement)

if ($args) {throw "Unknown arguments: $args"}

function PrepareVB {
$vb=new-object -com MSScriptControl.ScriptControl
$vb.language="VBScript"
$vb
}

if ((Get-Architecture -CurrentProcess) -eq 64) {
# Get path for this script
$me=$myinvocation.mycommand.path
# Build command as string to substitute values
$sb = " &'$me' -vbcode $vbcode -ExecuteStatement:`$$ExecuteStatement"
# Encode for safe command line passing
$encoded=[System.Convert]::ToBase64String([System.Text.Encoding]::UNICODE.GetBytes($sb))
# Invoke powershell 32-bit
&"$env:windir\syswow64\windowspowershell\v$($host.version.major).$($host.version.minor)\powershell.exe" -noprofile -EncodedCommand $encoded
return
}

$vb=PrepareVB
if ($ExecuteStatement.isPresent) {
$vb.ExecuteStatement($vbcode)
}
else {
$vb.Eval($vbcode)
}

Is this PowerShell Session a 32-bit or a 64-bit?

How can one identify whether the current PowerShell process is running the 32-bit version (x86) or the 64-bit version of PowerShell? Well first, why would you care? You are right, normally I do not care, but if I need to execute VBscript with Invoke-Script, I need to know as that only works on 32-bit Windows.

I'm now running Vista x64 - and that is actually a pleasure. For the first time, I feel my PC is responsive enough when running many applications. If you are interested, my PC is a Dell D830 with 4 GB RAM and a Intel Turbo Channel module having 1 GB. OK specs and nice performance.

One of the minor problems I have encountered is that MSScriptControl.ScriptControl used by Invoke-Script cannot be started from 64-bit PowerShell. I simply does not exist :(

So I set off hunting a way of finding out how to differentiate, so I could do something clever.

First, I looked at the $host variable, but that seemed to return the same info. Next, I looked at the current process. The only difference I found was the image path, there does not seem to be any flag indicating the execution mode. Strange, I would have expected that.

Before jumping on a image path test, I looked as wmi32_process as well. This did not really help me, but at least win32_operatingSystem.OSArchitecture help me figuring out the platform.

This all added up in Get-Architecture.ps1 which contains -



param([switch]$CurrentProcess)

if ($CurrentProcess.ispresent) {
$me=[diagnostics.process]::GetCurrentProcess()
if ($me.path -match '\\syswow64\\') {
32
}
else {
64
}
}
else {
$os=Get-WMIObject win32_operatingsystem
if ($os.OSArchitecture -eq "64-bit") {
64
}
else {
32
}
}


Example -



PS> powershell -noprofile {get-architecture -currentprocess}
64
PS> C:\WINDOWS\syswow64\windowspowershell\v1.0\powershell.exe -noprofile {get-architecture -currentprocess}
32
PS> powershell -noprofile {get-architecture}
64
PS> C:\WINDOWS\syswow64\windowspowershell\v1.0\powershell.exe -noprofile {get-architecture}
64
PS> powershell -noprofile {get-architecture -currentprocess}
64
PS> C:\WINDOWS\syswow64\windowspowershell\v1.0\powershell.exe -noprofile {get-architecture -currentprocess}
32


Suggestions for improvements are highly welcome!

Thursday, May 15, 2008

Interesting set of AudioCodes guides

AudioCodes has released a set of guides describing Advanced Topologies for OCS 2007 and Exchange 2007. There are several interesting scenarios including -

  • Cisco Call Manager connectivity to Office Communications Server 2007 and Exchange Server 2007
  • Single gateway for Office Communications Server 2007 and Exchange Server 2007
  • Asterisk IP-PBX connectivity to Office Communications Server 2007 and Exchange Server 2007
  • Enabling fax, modem and auxiliary devices for Office Communications Server 2007
  • PBX reduced trunk solution for Office Communications Server 2007
  • SIP trunking solution for Office Communications Server 2007

The last one about SIP Trunking looks interesting to some of my customers, it describes the following scenario -

“OCA” is a small, but growing retailer of outdoor clothing and apparel company located in New-Jersey, USA. OCA has a deployed Office Communications Server 2007 in its private network for enhanced communication within the company.
OCA decided to offer its employees Enterprise voice and to connect the company to the PSTN using a SIP trunk. OCA's major market is located in Japan and therefore, decided to select two ITSPs – TelIP located in USA and IPConnect located in Japan – for providing a SIP trunking solution. In addition, since OCA's Internet infrastructure frequently experienced interruption and loss of connection, the company decided to implement a telephony backup solution whereby in case of a connection failure with the SIP trunks, the calls are rerouted to the USA PSTN through a traditional T1 connection.

Wednesday, May 07, 2008

Using Consolas Font in your Command Window

Being a fan of using Lucida Console instead of the normal raster fonts, this is good news. You can enabled the Vista/Office 2007 Consolas font and use that. Read it all here in the IE blog.

Tuesday, May 06, 2008

New update for OC 2007 and security enhancement

My colleague Claus-Ole just pointed me to a new update on Office Communicator 2007.

This update fixes four problems and especially interesting is a fix for Terminal Server users and a enhancement to security in the High Security Policy mode, where the ABS, Custom Presence and Tabs URL's now require HTTPS. Following are the fixes -

951870 - Event IDs 8239 and 8206 are logged when you schedule and then cancel a meeting in Communicator 2007

949498 - Error message when a Communicator 2007 user sends a message that contains only Japanese characters to Communicator 2005 users: "<Username> cannot receive message in the format you used"

951871 - The presence status changes to Away for all Terminal Server users when an administrator locks the desktop or lets the screen saver run in Communicator 2007

951868 - Registry settings for certain protocols are overwritten, and Communicator 2007 becomes the default application for these protocols when you log on to Communicator 2007

Find the KB here and the download here.

Tuesday, April 29, 2008

Mac Messenger 7 available

As announced earlier Microsoft has updated the Mac Messenger client to also support Office Communications Server 2007. Following are a few snippets (Source) showing some of the OCS related functionality of the client (It still supports Windows Live)

P2P or multi-party audio/video conferencing -

Messenger Contacts

Searching the Address Book -

Messenger Contacts

Use of Mac OS X Bonjour  to detect location and ability to add personal messages

Messenger Chat

Download from here.