Sunday, January 03, 2010

Using PSCX from multiple users on same machine

I was having a problem with an automation script I was working on,
It used PowerShell and PowerShell community extensions (PSCX) and it worked fine of for me, but when other people used the same machine - it did not work.

after some looking around - the problem was that PSCX was installed from my user so it was automatically loaded on from my profile.

The resolution:

$pscxInstalled = $false;
$pscxLoaded = $false;
$registeredPSSnapins = Get-PSSnapin -registered
foreach ($registeredPSSnapin in $registeredPSSnapins) {
if ($registeredPSSnapin.Name -eq 'Pscx') {
write-host "PowerShell Community Extensions Found on system" -ForegroundColor green -BackgroundColor black
$pscxInstalled=$true;
$loadedPSSnapins = Get-PSSnapin
foreach ($loadedPSSnapin in $loadedPSSnapins) {
if ($loadedPSSnapin.Name -eq 'Pscx') {
$pscxLoaded=$true
write-host "PowerShell Community Extensions are loaded" -ForegroundColor green -BackgroundColor black
}
}
if (-not $pscxLoaded) {
write-host "Loading PowerShell Community Extensions from registered PSSnapin" -ForegroundColor green -BackgroundColor black
Add-PSSnapin Pscx

}
}
}

No comments:

 
Clicky Web Analytics