Powershell 脚本 ObjectNotFoundException CommandNotFoundException 路径

PowershellScript ObjectNotFoundException CommandNotFoundException Path

我用 SNK 文件签署我的 Dll。通过 visual studio build.

可以毫无问题地完成此操作

现在我想验证我确实给它们起了一个强名称的 DLL。我找到了 this powershell script,但我认为 powershell 讨厌我的路径。

Clear-Host

$path="C:\Users\MyName\Desktop\BuildOutput\Debug"
$snPath = "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\sn.exe"


foreach ($item in Get-ChildItem $path -Recurse -Include *.dll, *.exe)
{
    $reportLine = $item.FullName + "," + $item.Extension

#validate integrity
$expression = $snPath + ' -vf "' +  $item.FullName +'"'
$verify = Invoke-Expression $expression
$isValid = $verify | Select-String -Pattern "is valid"

if($isValid)
{
    $reportLine = $reportLine + ",ist signiert"
}
else
{
    $reportLine = $reportLine + ",ist nicht signiert"
}

#extract token
$expression = $snPath + ' -Tp "' +  $item.FullName +'"'
$result = Invoke-Expression $expression

$tokenString = $result | Select-String -Pattern "key token is"
if($tokenString)
{
    $token = $tokenString.Tostring().Substring(20)
    $reportLine = $reportLine + "," +$token
}

    $reportLine
} 

而我的错误是

In Line:1 Character:19

  • C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 ...
  • ~~~
    • CategoryInfo : ObjectNotFound: (x86:String) [], CommandNotFoundException
    • FullyQualifiedErrorId : CommandNotFoundException

我翻译了更多错误信息

The term "x86" was not recognized as the name of a cmdlet, function, script file, or executable. Check the spelling of the name, or if the path is correct (if included), and retry.

我必须逃避 x86 吗?如果是 - 我该怎么做?我试过了 this.

我试过了,结果总是一样。

$snPath = "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\sn.exe"

$snPath = ${env:CommonProgramFiles(x86)} + "\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\sn.exe"

$snPath =  ${env:ProgramFiles(x86)} + "\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\sn.exe"

$snPath = [Environment]::GetEnvironmentVariable("ProgramFiles(x86)") + + "\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\sn.exe"

Powershell 版本

专业:5
未成年人:1 建造:14393 修订:103

编辑

我修复了我的 snPath

我举了更多例子

更多错误信息

而不是

$expression = $snPath + ' -vf "' +  $item.FullName +'"'
$verify = Invoke-Expression $expression

你可以这样做:

$verify = & $snPath -vf $item.FullName