Copilotの回答
Add-Type @\u0026quot;
using System;
using System.Runtime.InteropServices;
public class Win32 {
[DllImport(\u0026quot;user32.dll\u0026quot;)]
public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
}
\u0026quot;@
# 最小化の定数
$SW_MINIMIZE = 6
# notepad.exe のすべてのプロセスを取得
$notepads = Get-Process notepad -ErrorAction SilentlyContinue
foreach ($np in $notepads) {
if ($np.MainWindowHandle -ne 0) {
# ウィンドウを最小化
[Win32]::ShowWindow($np.MainWindowHandle, $SW_MINIMIZE)
}
}