You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

61 lines
2.4 KiB

# ----------------------------------------------------------------------------------------------------------------------------------------------------------
function ParameterDefinitions {
param(
[Parameter(Mandatory)][string] $filename,
[Parameter(ValueFromRemainingArguments)] $opts
)
}
# see also https://vcsjones.dev/subject-interface-packages/
# ----------------------------------------------------------------------------------------------------------------------------------------------------------
function psmain {
[CmdletBinding()]
#Empty param block (extra params can be added)
param()
dynamicparam { GetDynamicParamDictionary ParameterDefinitions }
process {
#Called once - we get a single item being our PSBoundParameters dictionary
write-host "Bound Parameters:$($PSBoundParameters)"
switch ($PSBoundParameters.keys) {
'filename' {
write-host "got filename " $PSBoundParameters.filename
Set-Variable -Name $_ -Value $PSBoundParameters."$_"
if (($filename.length -eq 0) -or -not (test-path $filename)) {
write-host "file $filename not found"
exit 1
}
}
'opts' {
write-warning "Unused parameters: $($PSBoundParameters.$_)"
}
Default {
write-warning "Unhandled parameter -> [$($_)]"
}
}
foreach ($boundparam in $PSBoundParameters.GetEnumerator()) {
}
}
end {
# PSBoundParameters
write-host "filename:'$filename'"
$cert = Get-ChildItem -path Cert:\LocalMachine\My -CodeSigningCert | Where-Object {$_.subject -eq "CN=punkshell local"} | Select-Object -First 1
if ($cert.length -eq 0) {
write-host "No self signing certificate found (Cert:\LocalMachine\My)"
exit 2
}
write-host "Using Certificate"
write-host $cert | Select-Object FriendlyName,Thumbprint,Subject,NotAfter
write-host "Processing '$filename' ..."
try {
Write-Host $(Set-AuthenticodeSignature -FilePath $filename -Certificate $cert)
} catch {
throw $_.Exception.Message
}
write-host "-done-"
return $PSBoundParameters
}
}
write-host (psmain @args)