【问题标题】:PowershellScript ObjectNotFoundException CommandNotFoundException PathPowershell 脚本 ObjectNotFoundException CommandNotFoundException 路径
【发布时间】:2017-02-20 22:49:12
【问题描述】:

我用 SNK 文件签署我的 Dll。通过 Visual Studio 构建可以毫无问题地完成此操作。

现在我想验证我真正给它们起一个强名称的 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
} 

我的错误是

行内:1 个字符:19

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

我翻译了更多错误信息。

术语“x86”未被识别为 cmdlet、函数、脚本文件或可执行文件的名称。 检查名称的拼写,或者路径是否正确(如果包含),然后重试。

我必须逃离 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

我举了更多的例子

更多错误信息

【问题讨论】:

    标签: powershell exception powershell-2.0 powershell-3.0 sn


    【解决方案1】:

    而不是

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

    你可以这样做:

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

    【讨论】:

    • 感谢您的回复,但我得到了相同的结果。我什至在我的 Windows 资源管理器中再次尝试了该路径,但它是正确的。不知道为什么powershell脚本这么讨厌这条路。
    • 好吧,我使用了与您相同的路径 (C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\sn.exe)。对我来说有效。
    • 这个命令会打印什么东西吗? & "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\sn.exe" | Write-Output
    • 我也很困惑——为什么这不起作用。我对 Powershell 脚本很陌生。我执行了你的命令,它打印了 sn.exe 的可能性
    • 非常感谢!我修复了代码中的另一行,它正在工作!谢谢!
    猜你喜欢
    • 2021-01-20
    • 1970-01-01
    • 2016-12-11
    • 2014-01-23
    • 2020-10-13
    • 2010-11-14
    • 1970-01-01
    • 1970-01-01
    • 2019-08-25
    相关资源
    最近更新 更多