startup error when all scripts need to be signed

Topics: User Forum
Sep 3, 2007 at 12:18 AM
Hi All,

I've got powershell set up to only run scripts only after they've been signed. After installing PowerShell Community Extensions l had lots of errors until I signed profile.ps1 and all the sub scripts.

Now I'm down to the following error:

Split-Path : Cannot bind argument to parameter 'Path' because it is null.
At C:\Program Files\PowerShell Community Extensions\Profile\Environment.VisualStudio2005.ps1:39 char:21
+ $VSPath = split-path <<<< $VisualStudioKey.InstallDir -Parent | split-path -Parent
Join-Path : Cannot bind argument to parameter 'Path' because it is null.
At C:\Program Files\PowerShell Community Extensions\Profile\Environment.VisualStudio2005.ps1:40 char:20
+ $VCPath = join-path <<<< $VSPath 'VC'
Test-Path : Cannot bind argument to parameter 'Path' because it is null.
At C:\Program Files\PowerShell Community Extensions\Profile\Environment.VisualStudio2005.ps1:42 char:14
+ if (test-path <<<< $VSPath) {

Now I'm a novice at this so the problem may be very obvious... any suggestions would be appreceated.

Cheers, Neil
Coordinator
Sep 9, 2007 at 11:07 PM
Yeah there is a bug in this script that I introduced :-(. If you don't have VS 2005 installed it will fail like this. Can you try the following version of this script and see if it fixes the issue (modulo signing):

if (Test-Path Variable:__PscxProfileRanOnce) {
return
}

& {
$VisualStudioVersion = Version'8.0.50727'

# Determine the base install path
if (IntPtr::Size -eq 8)
{
$regKeyPath = join-path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\VisualStudio' $VisualStudioVersion.ToString(2)
}
else
{
$regKeyPath = join-path 'HKLM:\SOFTWARE\Microsoft\VisualStudio' $VisualStudioVersion.ToString(2)
}

$VisualStudioKey = get-itemproperty $regKeyPath -ErrorAction SilentlyContinue
if (!$VisualStudioKey) {
return
}

$VSPath = split-path $VisualStudioKey.InstallDir -Parent | split-path -Parent
$VCPath = join-path $VSPath 'VC'

if (test-path $VSPath) {

# Determine the configured version of the CLR
$FrameworkVersion = Version($VisualStudioKey.'CLR Version'.Substring(1))

# Set up the base directory environment variables
$Env:FrameworkVersion = 'v' + $FrameworkVersion.ToString(3)
$Env:DevEnvDir = $VisualStudioKey.InstallDir
$Env:VSInstallDir = $VSPath
$Env:VCInstallDir = $VCPath

# Set the paths for the Framework and SDK directories
$FrameworkKey = get-itemproperty HKLM:\SOFTWARE\Microsoft\.NETFramework
$Env:FrameworkDir = $FrameworkKey.InstallRoot
$Env:FrameworkSDKDir = $FrameworkKey.'sdkInstallRootv2.0'

# Path
Add-PathVariable 'Path' @(
($Env:DevEnvDir),
(join-path $VCPath 'BIN'),
(join-path $VCPath 'PlatformSDK\bin'),
(join-path $VCPath 'VCPackages'),

(join-path $VSPath 'Common7\Tools'),
(join-path $VSPath 'Common7\Tools\bin'),

(join-path $Env:FrameworkSDKDir 'bin'),
(join-path $Env:FrameworkDir $Env:FrameworkVersion)
)

# Include
Add-PathVariable 'Include' @(
(join-path $VCPath 'AtlMfc\Include'),
(join-path $VCPath 'Include'),
(join-path $VCPath 'PlatformSDK\Include'),
(join-path $Env:FrameworkSDKDir 'Include')
)

# Lib
Add-PathVariable 'Lib' @(
(join-path $VCPath 'Lib'),
(join-path $VCPath 'AtlMfc\Lib'),
(join-path $VCPath 'PlatformSDK\Lib'),
(join-path $Env:FrameworkSDKDir 'Lib')
)

# LibPath
Add-PathVariable 'LibPath' @(
(join-path $VCPath 'AtlMfc\Lib'),
(join-path $Env:FrameworkDir $Env:FrameworkVersion)
)
}
}
Oct 5, 2007 at 12:16 PM
Hi.

I was receiving the same errors as neilm1144 above and found that the issue was that I had only the Microsoft .NET Framework v2.0 SDK installed on the machine, not VisusalStudio 2005. The SDK adds the VisualStudio registry key but not the InstallDir value. I found inserting this extra check at line 38 in Environment.VisualStudio2005.ps1 solved the issue:

if (!$VisualStudioKey.InstallDir) {
remove-variable VisualStudioVersion -Scope Global
return
}

Hope this helps.