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.