ファイル選択ダイアログ

変数を設定 [$PS; 値:

"

$Arguments={-sta},{Add-Type -Assembly System.Windows.Forms;

$dialog = New-Object System.Windows.Forms.OpenFileDialog;

$dialog.InitialDirectory = 'C:\';

$dialog.Filter = 'テキストファイル|*.txt|Csvファイル|*.csv';

$dialog.Title = 'ファイルを選択してください';

if ($dialog.ShowDialog() -eq 'OK') {

$PATH = $dialog.FileName;

}

$PATH;};

$pinfo = New-Object System.Diagnostics.ProcessStartInfo;

$pinfo.FileName = 'PowerShell';

$pinfo.RedirectStandardError = $true;

$pinfo.RedirectStandardOutput = $true;

$pinfo.CreateNoWindow = $true ;

$pinfo.UseShellExecute = $false;

$pinfo.Arguments = $Arguments;

$p = New-Object System.Diagnostics.Process;

$p.StartInfo = $pinfo;

$p.Start() | Out-Null;

$p.WaitForExit();

$stdout = $p.StandardOutput.ReadToEnd();

$stderr = $p.StandardError.ReadToEnd();

<#Write-Host \"stdout: $stdout\"

Write-Host \"stderr: $stderr\"

Write-Host \"exit code: \" + $p.ExitCode#>

$stdout ;

"]

変数を設定 [$filePath; 値: SMPS_ExecSync( $PS ) ]

参考

https://letspowershell.blogspot.jp/2015/06/powershell_10.html

http://yaplog.jp/consadole_spo/archive/110