Skip to content

Instantly share code, notes, and snippets.

@vitran96
Created June 23, 2023 07:30
Show Gist options
  • Save vitran96/e48bdea6612605acd45de366603a224d to your computer and use it in GitHub Desktop.
Save vitran96/e48bdea6612605acd45de366603a224d to your computer and use it in GitHub Desktop.
param (
[Parameter(Position = 0, Mandatory = $true)]
[ValidateScript({Test-Path $_ -PathType 'Leaf'})]
[string]$originalPemPath
)
$fileName = (Get-Item -Path $originalPemPath).BaseName
# Get the current user's home directory
$homeDirectory = [Environment]::GetFolderPath("UserProfile")
# Create the destination path for the modified .pem file
$destination = Join-Path -Path $homeDirectory -ChildPath ".ssh\$fileName.pem"
# Read the original .pem file contents
$pemContent = Get-Content -Path $originalPemPath
# Remove any lines that start with "Proc-Type:" or "DEK-Info:"
$pemContent = $pemContent | Where-Object { $_ -notmatch "^(Proc-Type:|DEK-Info:)" }
# Write the modified .pem file contents to the new file
$pemContent | Set-Content -Path $destination
# Set the permissions of the modified .pem file to read-only for the current user
# $acl = Get-Acl -Path $destination
# $identity = [System.Security.Principal.NTAccount]("$env:USERDOMAIN\$env:USERNAME")
# $accessRule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule($identity, 'Read', 'Allow')
# $acl.SetAccessRule($accessRule)
# Set-Acl -Path $destination -AclObject $acl
Write-Host "$fileName.pem has been installed"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment