0

I sign my Dlls with SNK-Files. This is done without problems through the visual studio build.

Now i want to validate the DLLs that I really gave them a strong name. I found this powershell script, but I think powershell hates my path.

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
} 

And my error is

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

I translated more error information.

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.

Do I have to escape the x86? And if yes - How can i do it? I tried this.

I tried this with allways the same result.

$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 Version

Major: 5
Minor: 1 Build: 14393 Revision: 103

EDIT

I fixed my snPath

I gave more examples

more error Information

Peter
  • 1,655
  • 22
  • 44

1 Answers1

2

instead of

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

you could do it like that:

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

Maximilian Etti
  • 230
  • 1
  • 9
  • Thank you for your response, but i get the same result. I even tried the path again in my windows explorer, but it is the right one. I don't know why powershell script hates this path so much. – Peter Oct 12 '16 at 08:42
  • well I used the same path as you (`C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\sn.exe`). for me that worked. – Maximilian Etti Oct 12 '16 at 08:54
  • does this command prints something? `& "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\sn.exe" | Write-Output` – Maximilian Etti Oct 12 '16 at 08:58
  • I am really confused too - why this isnt working. I am fresh into Powershell Scripts. I executed your command and it prints me the possiblitys of sn.exe – Peter Oct 12 '16 at 09:01
  • Thank you so much! I fixed the other line in the Code and it is working! Thank you ! – Peter Oct 12 '16 at 09:10