Bird
0
0

You want to sign multiple scripts in a folder using the same certificate. Which PowerShell snippet correctly signs all .ps1 files?

hard📝 Application Q15 of 15
PowerShell - Scripting Best Practices
You want to sign multiple scripts in a folder using the same certificate. Which PowerShell snippet correctly signs all .ps1 files?
AGet-ChildItem -Path . -Filter '*.ps1' | ForEach-Object { Set-AuthenticodeSignature -FilePath $_.FullName -Certificate $cert }
BSet-AuthenticodeSignature -FilePath '*.ps1' -Certificate $cert
CForEach ($file in '*.ps1') { Set-AuthenticodeSignature -FilePath $file -Certificate $cert }
DGet-Content '*.ps1' | Set-AuthenticodeSignature -Certificate $cert
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct way to get all .ps1 files

    Get-ChildItem -Filter '*.ps1' lists all script files in the folder.
  2. Step 2: Apply signing to each file

    Using ForEach-Object to call Set-AuthenticodeSignature on each file with the certificate is correct.
  3. Step 3: Check other options

    Set-AuthenticodeSignature -FilePath '*.ps1' -Certificate $cert tries to sign a wildcard path directly (invalid). ForEach ($file in '*.ps1') { Set-AuthenticodeSignature -FilePath $file -Certificate $cert } treats '*.ps1' as a string list (wrong). Get-Content '*.ps1' | Set-AuthenticodeSignature -Certificate $cert pipes file content, not file paths (wrong).
  4. Final Answer:

    Get-ChildItem -Path . -Filter '*.ps1' | ForEach-Object { Set-AuthenticodeSignature -FilePath $_.FullName -Certificate $cert } -> Option A
  5. Quick Check:

    Use Get-ChildItem + ForEach-Object to sign all scripts [OK]
Quick Trick: Use Get-ChildItem and ForEach-Object to sign multiple files [OK]
Common Mistakes:
  • Trying to sign wildcard paths directly
  • Using file content instead of file paths
  • Treating '*.ps1' as a list of files

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes