Files
2025-11-21 17:17:42 +01:00

957 B

Description

This function will convert a PowerShell script to a Batch file

The Function

[PowerShell-2-Batch]

Using this function will convert your powershell payload over to Base64 and then change the extension on it to be a .BAT file

Make the conversion with this function using the following syntax:

P2B -Path "C:\Users\User\Desktop\example.ps1"

or

"C:\Users\User\Desktop\example.ps1" | P2B
function P2B {
    param
    (
        [Parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName)]
        [string]
        $Path
    )
 
    process
    {
        $encoded = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes((Get-Content -Path $Path -Raw -Encoding UTF8)))
        $newPath = [Io.Path]::ChangeExtension($Path, ".bat")
        "@echo off`npowershell -w h -NoP -NonI -Exec Bypass -enc $encoded" | Set-Content -Path $newPath -Encoding Ascii
    }
}