---
title: 'PowerShellで作る Dashboard アプリのエントリーポイント解説'
url: 'https://automationse.net/powershell-wpf-entrypoint-relaunch-sta'
markdown: 'https://automationse.net/powershell-wpf-entrypoint-relaunch-sta.md'
date: '2025-09-28'
description: '本記事では、PowerShellで構築された Dashboardアプリのエントリーポイントスクリプト Main.ps1 を解説します。このスクリプトは、アプリ全体を正しく起動させるための「玄関口」として機能します。 ツールをダッシュボードで可視化してみます。 スクリプトのポイント解説 1. STA強制再起動 PowerShellは通常MT…'
taxonomy:
  category:
    - IT関連
  tag:
    - PowerShell
    - アプリ
---

# PowerShellで作る Dashboard アプリのエントリーポイント解説

## [PowerShellで作る Dashboard アプリのエントリーポイント解説](https://automationse.net/powershell-wpf-entrypoint-relaunch-sta)

  公開日 2025.09.28 更新日 2025.09.28  [PowerShell](https://automationse.net/tag:PowerShell#body-wrapper) [アプリ](https://automationse.net/tag:%E3%82%A2%E3%83%97%E3%83%AA#body-wrapper)  

 本記事では、PowerShellで構築された **Dashboardアプリのエントリーポイントスクリプト** `Main.ps1` を解説します。
このスクリプトは、アプリ全体を正しく起動させるための「玄関口」として機能します。

ツールをダッシュボードで可視化してみます。

## スクリプトのポイント解説

### 1. **STA強制再起動**

- PowerShellは通常MTAモードで動作しますが、WPFアプリは **STA必須**。
- `Invoke-RelaunchSTA` 関数で必ず `-STA` 付きで再起動する仕組みを用意。

### 2. **ログ出力機能**

- `Write-Log` / `Write-ErrLog` により、実行経過をコンソールとログファイル両方に保存。
- 実行トラブルの解析が容易。

### 3. **WPF関連アセンブリのロード**

- `PresentationCore`, `PresentationFramework`, `WindowsBase` を追加ロード。
- XAMLベースのUIを使用可能に。

### 4. **モジュール読み込み**

- `Launcher.ps1` や `Dashboard.ps1` など、アプリ機能の中核モジュールをインポート。

#### `Dashboard.ps1`

#### `Dashboard.xaml`

#### Launcher.ps1

### 5. **スタイルリソースの適用**

- `Styles.xaml` をロードし、WPFアプリのUIスタイルを統一。

#### Styles.xaml

#### MainWindows.xaml

## まとめ

この `Main.ps1` は、単なる起動スクリプトではなく **「WPFアプリをPowerShellで安全に起動するためのブートストラップ」** として設計されています。
特にSTAモードの保証とログ出力機能は、実運用において非常に重要なポイントです。

 [ Previous Post](https://automationse.net/powershell-url-popup-script) [Next Post ](https://automationse.net/wpf-dashboard-json-powershell)

---

## Navigation

- Parent: [WordPress Import](https://automationse.net/wordpress-import.md)
- Previous: [WPF ダッシュボードを JSON を読み込んで表示するGUIアプリ（PowerShell + XAML）](https://automationse.net/wpf-dashboard-json-powershell.md)
- Next: [ブラウザ上のリンク先URLをポップアップ表示するPowerShellスクリプト](https://automationse.net/powershell-url-popup-script.md)
