PoshCode Logo PowerShell Code Repository

Get/Set Signature (CTP2) (modification of post by view diff)
View followups from Joel Bennett | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/436"></script>download | new post

Wrappers for the Get-AuthenticodeSignature and Set-AuthenticodeSignature which properly parse paths and don’t kill your pipeline and script when you hit a folder by accident…

  1. #requires -version 2.0
  2. CMDLET Set-AuthenticodeSignature -snapin Huddled.BetterDefaults {
  3. PARAM (
  4.    [Parameter(Position=1, Mandatory=$true, ValueFromPipelineByPropertyName=$true)]
  5.    [Alias("FullName")]
  6.    [ValidateScript({
  7.       if((resolve-path .\breaking.ps1).Provider.Name -ne "FileSystem") {
  8.          throw "Specified Path is not in the FileSystem: '$_'"
  9.       }
  10.       if(!(Test-Path -PathType Leaf $_)) {
  11.          throw "Specified Path is not a File: '$_'"
  12.       }
  13.       return $true
  14.    })]
  15.    [string]
  16.    $Path
  17. ,
  18.    $Certificate=$(ls cert:\CurrentUser\my\0DA3A2A2189CD74AE371E6C57504FEB9A59BB22E)
  19. )
  20.    Microsoft.PowerShell.Security\Set-AuthenticodeSignature -Certificate $Certificate -FilePath $Path  
  21. }
  22.  
  23. CMDLET Get-AuthenticodeSignature -snapin Huddled.BetterDefaults {
  24. PARAM (
  25.    [Parameter(Position=1, Mandatory=$true, ValueFromPipelineByPropertyName=$true)]
  26.    [Alias("FullName")]
  27.    [ValidateScript({
  28.       if((resolve-path .\breaking.ps1).Provider.Name -ne "FileSystem") {
  29.          throw "Specified Path is not in the FileSystem: '$_'"
  30.       }
  31.       if(!(Test-Path -PathType Leaf $_)) {
  32.          throw "Specified Path is not a File: '$_'"
  33.       }
  34.       return $true
  35.    })]
  36.    [string]
  37.    $Path
  38. )
  39.    Microsoft.PowerShell.Security\Get-AuthenticodeSignature -FilePath $Path  
  40. }
  41.  
  42. Export-ModuleMember Set-AuthenticodeSignature,Get-AuthenticodeSignature

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me