LoginSignup
0
0

実行ポリシー実験 自己著名証明書作成

Posted at

PowerShell 7.4.1で実行

PS C:\Users\(ユーザ名)>cd C:\Users\(ユーザ名)\Desktop\実行ポリシー実験

PS C:\Users\(ユーザ名)\Desktop\実行ポリシー実験> $cert = New-SelfSignedCertificate -Subject "CN=hoge" `
                -KeyAlgorithm RSA -KeyLength 2048 -Type CodeSigningCert `
                -CertStoreLocation "Cert:\LocalMachine\My\" -NotAfter 2040/12/31
PS C:\Users\(ユーザ名)\Desktop\実行ポリシー実験> Move-Item "Cert:\LocalMachine\My\$($cert.Thumbprint)" "Cert:\LocalMachine\Root"
PS C:\Users\(ユーザ名)\Desktop\実行ポリシー実験> $cert=Get-ChildItem Cert:\LocalMachine\Root -CodeSigningCert
PS C:\Users\(ユーザ名)\Desktop\実行ポリシー実験> $cert.Thumbprint[0]
文字列




PS C:\Users\(ユーザ名)\Desktop\実行ポリシー実験>$directoryPath = "Cert:\CurrentUser\Root"
PS C:\Users\(ユーザ名)\Desktop\実行ポリシー実験>$fullPath = Join-Path -Path $directoryPath -ChildPath $cert.Thumbprint[0]
PS C:\Users\(ユーザ名)\Desktop\実行ポリシー実験> Set-AuthenticodeSignature -FilePath C:\Users\(ユーザ名)\Desktop\実行ポリシー実験\test3.ps1 -Certificate (Get-ChildItem -Path $fullPath)

    Directory: C:\Users\(ユーザ名)\Desktop\実行ポリシー実験

SignerCertificate                         Status                    StatusMessage             Path
-----------------                         ------                    -------------             ----
文字列  Valid                     Signature verified.       test3.ps1

PS C:\Users\(ユーザ名)\Desktop\実行ポリシー実験> .\test3.ps1
Hello World!!
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0