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

1 Answer 1

2

instead of

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

you could do it like that:

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

Sign up to request clarification or add additional context in comments.

5 Comments

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.
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.
does this command prints something? & "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\sn.exe" | Write-Output
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
Thank you so much! I fixed the other line in the Code and it is working! Thank you !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.