# Function to check and add alias function Check-And-Add-Alias { $profilePath = $PROFILE if (!(Test-Path -Path $profilePath)) { New-Item -ItemType File -Path $profilePath -Force | Out-Null } $profileContent = Get-Content -Path $profilePath -ErrorAction SilentlyContinue $aliasExists = $profileContent -match "Set-Alias -Name psh -Value powershell" if (-not $aliasExists) { Add-Content -Path $profilePath -Value "Set-Alias -Name psh -Value powershell" Write-Output "Alias 'psh' has been added to the profile." } else { Write-Output "Alias 'psh' already exists in the profile." } } # Check for admin rights and elevate if necessary if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Write-Output "Administrator rights are required. Displaying UAC prompt." Start-Process -FilePath "powershell.exe" -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs exit } Write-Output "Running with administrator rights." # Display operations and confirm $operations = @" The following operations will be performed: 1. Add 'psh' alias to PowerShell profile. 2. Register 'psh.exe' in App Paths registry. "@ Write-Output $operations $yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", "Proceed with the operations." $no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", "Cancel the operations." $print = New-Object System.Management.Automation.Host.ChoiceDescription "&Print", "Display the code to be executed." $options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no, $print) $code = @" # Add alias to PowerShell profile `$profilePath = `$PROFILE if (!(Test-Path -Path `$profilePath)) { New-Item -ItemType File -Path `$profilePath -Force | Out-Null } Add-Content -Path `$profilePath -Value "Set-Alias -Name psh -Value powershell" # Register in App Paths registry `$regPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\psh.exe" if (!(Test-Path `$regPath)) { New-Item -Path `$regPath -Force | Out-Null } Set-ItemProperty -Path `$regPath -Name "(default)" -Value "%SystemRoot%\system32\WindowsPowerShell\v1.0\PowerShell.exe" -Type ExpandString "@ while ($true) { $result = $host.ui.PromptForChoice("Confirm Operations", "Do you want to proceed?", $options, 0) switch ($result) { 0 { Write-Output "Proceeding with operations..." # Check and add alias (without admin rights) Check-And-Add-Alias # Register in App Paths registry $regPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\psh.exe" if (!(Test-Path $regPath)) { New-Item -Path $regPath -Force | Out-Null } Set-ItemProperty -Path $regPath -Name "(default)" -Value "%SystemRoot%\system32\WindowsPowerShell\v1.0\PowerShell.exe" -Type ExpandString Write-Output "Registered 'psh.exe' in App Paths." Write-Output "All operations completed. You can now launch PowerShell using the 'psh' command." return } 1 { Write-Output "Operation cancelled." return } 2 { Write-Output "`nHere's the code that will be executed:`n" Write-Output $code Write-Output "" } } }