Skip to content
KitploitKITPLOIT
ツールブログ
提出
ツールブログ
提出

ハッキング、侵入テスト、サイバーセキュリティツールをあなたのセキュリティアーセナルに!

Kitploitはハッキング、サイバーセキュリティ、ペネトレーションテストのツールディレクトリです。最新のプロジェクトアップデートを見つけて、脆弱性の発見、システム分析、テストの自動化、セキュリティの強化を行いましょう。

··フィード·お問い合わせ·プライバシー·© 2026 Kitploit

ツールディレクトリ

カテゴリ

すべてのカテゴリを見る
Loading categories
PS2EXE — PowerShellスクリプトを実行可能ファイルにコンパイルするモジュール | Kitploit
ツール/GitHubGitHub/mscholtes/ps2exe
ペイロード生成スクリプトと自動化ユーティリティとフレームワーク
GitHubmscholtes/ps2exe

PS2EXE

PowerShellスクリプトを実行可能ファイルにコンパイルするモジュール

リポジトリを見る
1.8k24763ヶ月前Kitploit レビュー済み

人気

すべて見る →

コミュニティで最も使われているツールを見つけましょう。

すべてのツールを探索

ツールコレクションを閲覧

すべてのツールを見る →
共有

AI free repository - 人工知能は創造性と私たちの自然を殺しています!

PS2EXE

Ingo Karsteinの素晴らしいスクリプトを拡張し、GUIサポートを追加しました。GUI出力と入力は1つのスイッチで有効になり、実際のWindows実行可能ファイルが生成されます。PowerShell 5.x互換のスクリプトのみをコンパイルします。オプションのグラフィカルフロントエンドWin-PS2EXEも利用可能です。

モジュールバージョン。

スクリプトベースのバージョンはこちら(https://github.com/MScholtes/TechNet-Gallery)にあります。

著者: Markus Scholtes

バージョン: 1.0.18

日付: 2026-06-06

インストール

root@kitploit:~
PS C:\> Install-Module ps2exe

またはこちらからダウンロード: https://www.powershellgallery.com/packages/ps2exe/。

使用方法

root@kitploit:~
  Invoke-ps2exe .\source.ps1 .\target.exe

または

root@kitploit:~
  ps2exe .\source.ps1 .\target.exe

"source.ps1" を実行可能ファイル target.exe にコンパイルします(".\target.exe" を省略すると、出力は ".\source.exe" に書き込まれます)。

またはグラフィカルフロントエンドを起動するには、次のように入力します。

root@kitploit:~
  Win-PS2EXE

パラメーター

root@kitploit:~
ps2exe [-inputFile] '<file_name>' [[-outputFile] '<file_name>']
       [-prepareDebug] [-x86|-x64] [-lcid <id>] [-STA|-MTA] [-noConsole] [-conHost] [-UNICODEEncoding]
       [-credentialGUI] [-iconFile '<filename>'] [-$embedFiles <hashtable>] [-title '<title>'] [-description '<description>']
       [-company '<company>'] [-product '<product>'] [-copyright '<copyright>'] [-trademark '<trademark>']
       [-version '<version>'] [-configFile] [-noOutput] [-noError] [-noVisualStyles] [-exitOnCancel]
       [-DPIAware] [-requireAdmin] [-supportOS] [-virtualize] [-longPaths]
root@kitploit:~
      inputFile = Powershell script that you want to convert to executable (file has to be UTF8 or UTF16 encoded)
     outputFile = destination executable file name or folder, defaults to inputFile with extension '.exe'
   prepareDebug = create helpful information for debugging
     x86 or x64 = compile for 32-bit or 64-bit runtime only
           lcid = location ID for the compiled executable. Current user culture if not specified
     STA or MTA = 'Single Thread Apartment' or 'Multi Thread Apartment' mode
      noConsole = the resulting executable will be a Windows Forms app without a console window
        conHost = force start with conhost as console instead of Windows Terminal (disables redirections)
UNICODEEncoding = encode output as UNICODE in console mode
  credentialGUI = use GUI for prompting credentials in console mode
       iconFile = icon file name for the compiled executable
     embedFiles = files to embed given as hash, will be extracted to key of hash, source file names must be unique
                  (e.g. -embedFiles @{'Targetfilepath'='Sourcefilepath'} )
          title = title information (displayed in details tab of Windows Explorer's properties dialog)
    description = description information (not displayed, but embedded in executable)
        company = company information (not displayed, but embedded in executable)
        product = product information (displayed in details tab of Windows Explorer's properties dialog)
      copyright = copyright information (displayed in details tab of Windows Explorer's properties dialog)
      trademark = trademark information (displayed in details tab of Windows Explorer's properties dialog)
        version = version information (displayed in details tab of Windows Explorer's properties dialog)
     configFile = write config file (<outputfile>.exe.config)
       noOutput = the resulting executable will generate no standard output (includes verbose and information channel)
        noError = the resulting executable will generate no error output (includes warning and debug channel)
 noVisualStyles = disable visual styles for a generated windows GUI application (only with -noConsole)
   exitOnCancel = exits program when Cancel or "X" is selected in a Read-Host input box (only with -noConsole)
       DPIAware = if display scaling is activated, GUI controls will be scaled if possible (only with -noConsole)
   requireAdmin = if UAC is enabled, compiled executable run only in elevated context (UAC dialog appears if required)
      supportOS = use functions of newest Windows versions (execute [Environment]::OSVersion to see the difference)
     virtualize = application virtualization is activated (forcing x86 runtime)
      longPaths = enable long paths ( > 260 characters) if enabled on OS (works only with Windows 10)

生成された実行可能ファイルには、次の予約パラメーターがあります。

root@kitploit:~
-? [<MODIFIER>]     Powershell help text of the script inside the executable. The optional parameter combination
                    "-? -detailed", "-? -examples" or "-? -full" can be used to get the appropriate help text.
-debug              Forces the executable to be debugged. It calls "System.Diagnostics.Debugger.Launch()".
-extract:<FILENAME> Extracts the powerShell script inside the executable and saves it as FILENAME.
                    The script will not be executed.
-wait               At the end of the script execution it writes "Hit any key to exit..." and waits for a key to be pressed.
-end                All following options will be passed to the script inside the executable.
                    All preceding options are used by the executable itself and will not be passed to the script.

備考

PowerShell Coreの使用:

PS2EXEはPowerShell Coreでも使用できます。そのためには、上記のようにPowerShell CoreにPS2EXEモジュールをインストールします。しかし、.Net Coreにはコンパイラが付属していないため、.Net Frameworkのコンパイラが使用されます(Windowsには.Net FrameworkとPowerShell 5.1が含まれています)。

このため、PS2EXEはPowerShell 5.1互換のスクリプトのみをコンパイルし、.Net 4.xバイナリを生成しますが、依存関係なしにサポートされているすべてのWindows OSで直接使用できます。

コンパイルされた実行可能ファイルへのファイルの埋め込み:

-embedFiles パラメーターにファイルパスのハッシュテーブルを指定すると、それらのファイルがコンパイルされた実行可能ファイルに埋め込まれます。 実行可能ファイルの起動時に、それらのファイルは指定されたパスにディスクに書き込まれます。例: -embedFiles @{'Targetfilepath1'='Sourcefilepath1';'Targetfilepath2'='Sourcefilepath2'}。 ソースファイル名は一意でなければなりません。絶対パスと相対パスの両方が使用できます。ターゲットパスが '.\' で始まる相対パスの場合、実行可能ファイルからの相対パスとして解釈され、先頭の '.\' がない場合は実行時の現在のパスからの相対パスとして解釈されます。 必要に応じて、起動時にディレクトリが自動的に作成されます。ターゲットパスでは、%TEMP% や %APPDATA% のようなcmd.exe形式の環境変数が実行時に展開されます。 埋め込まれたファイルの作成に失敗すると、コンパイルされた実行可能ファイルの実行は直ちに停止します。

実装されていないコマンドレットのリスト:

基本的な入出力コマンドはPS2EXE用にC#で書き直す必要がありました。コンソールモードの Write-Progress(作業量が多すぎる)および Start-Transcript/Stop-Transcript(Microsoftによる適切なリファレンス実装がない)は実装されていません。

GUIモードの出力フォーマット:

デフォルトでは、PowerShellのコマンドレットの出力は行ごとにフォーマットされます(文字列の配列として)。コマンドが10行の出力を生成し、GUI出力を使用する場合、それぞれのOK待ちで10個のメッセージボックスが表示されます。これを防ぐには、コマンドを Out-String コマンドレットにパイプします。これにより、出力が10行の文字列配列に変換され、すべての出力が1つのメッセージボックスに表示されます(例: dir C:\ | Out-String)。

設定ファイル:

PS2EXEは、生成された実行可能ファイルの名前 + ".config" という設定ファイルを作成できます。ほとんどの場合、これらの設定ファイルは不要です。これらは、使用する.Net Frameworkのバージョンを指定するマニフェストです。通常は最新の.Net Frameworkを使用するため、設定ファイルなしで実行可能ファイルを実行してみてください。

パラメーター処理:

コンパイルされたスクリプトは、元のスクリプトと同様にパラメーターを処理します。Windows環境では、すべての実行可能ファイルのパラメーターは型 STRING であるという制限があります。パラメーターの型に暗黙の変換がない場合は、スクリプト内で明示的に変換する必要があります。同じ制限で、実行可能ファイルにコンテンツをパイプすることもできます(パイプされたすべての値は型 STRING です)。

パスワードのセキュリティ:

コンパイルされたスクリプトにパスワードを保存しないでください! -extract パラメーターを使用すると、簡単にスクリプトを逆コンパイルできます。例えば

root@kitploit:~
Output.exe -extract:C:\Output.ps1

は、Output.exe に保存されているスクリプトを逆コンパイルします。また、スクリプトは(意図的に)実行可能ファイル内に平文で保存されていることに注意してください!

スクリプト変数:

PS2EXEはスクリプトを実行可能ファイルに変換するため、スクリプト関連の変数は使用できなくなります。変数 $MyInvocation はスクリプトとは異なる値に設定されます。 特に変数 $PSScriptRoot は空です - 代わりに $ScriptRoot を使用できます。 次のコード行を使用すると、コンパイルされているかどうかに関係なく $PSScriptRoot を取得できます。

root@kitploit:~
if (!$PSScriptRoot) { $PSScriptRoot = $ScriptRoot }

-noConsoleモードでのバックグラウンドウィンドウ:

-noConsole モードのスクリプトで外部ウィンドウが開かれると(Get-Credential や cmd.exe シェルを必要とするコマンドなど)、次のウィンドウがバックグラウンドで開かれます。 理由は、外部ウィンドウを閉じるときに、Windowsが親ウィンドウをアクティブにしようとするためです。コンパイルされたスクリプトにはウィンドウがないため、代わりにコンパイルされたスクリプトの親ウィンドウ(通常はExplorerやPowerShellのウィンドウ)がアクティブになります。 回避策として、$Host.UI.RawUI.FlushInputBuffer() はアクティブ化できる非表示ウィンドウを開きます。次の $Host.UI.RawUI.FlushInputBuffer() の呼び出しでこのウィンドウが閉じられます(以下同様)。 次の例では、"ipconfig | Out-String" の単一呼び出しのようにバックグラウンドでウィンドウが開かれることはありません。

root@kitploit:~
$Host.UI.RawUI.FlushInputBuffer()
ipconfig | Out-String
$Host.UI.RawUI.FlushInputBuffer()

変更履歴:

1.0.18 - 2026-06-06

  • 事前定義変数 $ScriptRoot を $PSScriptRoot の代替として追加
  • Win-PS2EXEの新しいバージョン

1.0.17 / 2025-08-21

  • コンパイルされた実行可能ファイルにファイルを埋め込むための新しいパラメーター -embedFiles を追加

1.0.16 / 2025-07-20

  • コンパイルされた実行可能ファイルをWindows Terminalの代わりにConhostで強制的に起動する新しいパラメーター -conHost を追加

1.0.15 / 2025-01-05

  • PowerShell Coreのみで使用する場合、PowerShell 5.1にもモジュールをインストールする必要はありません

1.0.14 / 2024-09-15

  • コンパイルされた実行可能ファイルに元のPowerShellスクリプトのヘルプを表示する新しいパラメーター -? を追加
  • GUIモードでは、ウィンドウのタイトルがアプリケーションタイトルになります(パラメーター -title でコンパイル時に設定した場合)

1.0.13 / 2023-09-26

  • スクリプトのディレクトリ名で [ と ] がサポートされるようになりました
  • ソースファイルが16MBを超える場合でも対応可能(必要な方のために)
  • Win-PS2EXEに新しい追加パラメーターテキストフィールドを追加

1.0.12 / 2022-11-22

  • noConsoleモードでWinFormsのスケーリングをサポートする新しいパラメーター -winFormsDPIAware を追加(Windows 10以降のみ)

1.0.11 / 2021-11-21

  • 24文字を超えるパスワードのエラーを修正
  • noConsoleモードでのスケーリングをサポートする新しいパラメーター -DPIAware を追加
  • 入力ボックスでキャンセル時にプログラムの実行を停止する新しいパラメーター -exitOnCancel を追加(noConsoleモードのみ)

1.0.10 / 2021-04-10

  • パラメーター outputFile がターゲットフォルダー(ファイル名なし)を受け入れるようになりました

1.0.9 / 2021-02-28

  • 出力をUNICODEとして出力する新しいパラメーター UNICODEEncoding を追加
  • パラメーター debug を prepareDebug に変更
  • ついに高度なパラメーターを使用する勇気が出ました

1.0.8 / 2020-10-24

  • リファクタリング

1.0.7 / 2020-08-21

  • 1つのパイプライン内での同時進行バーのバグ修正

1.0.6 / 2020-08-10

  • 選択肢のプロンプトがPowerShellと同様の動作に(コンソールモードのみ)
  • PowerShell Coreの(限定的な)サポート(バックグラウンドでWindows PowerShellを起動)
  • 負のパラメーター値の処理を修正
  • アニメーション進行バーのサポート(noConsoleモードのみ)

1.0.5 / 2020-07-11

  • ネストされた進行バーのサポート(noConsoleモードのみ)

1.0.4 / 2020-04-19

  • GUIアプリケーションのデフォルトとしてApplication.EnableVisualStyles() を有効化、これを防ぐ新しいパラメーター -noVisualStyles を追加

1.0.3 / 2020-02-15

  • git diffを可能にするためファイルをUTF-16からUTF-8に変換
  • コンソールモードのセキュア文字列要求で制御キーを無視

1.0.2 / 2020-01-08

  • GitHubにサンプルを追加

1.0.1 / 2019-12-16

  • ps2exe.ps1 と Win-PS2EXE の「GUIウィンドウの無制限幅」問題を修正

1.0.0 / 2019-11-08

  • 最初の安定版モジュールバージョン

0.0.0 / 2019-09-15

  • 実験的
ツールをダウンロード