param($url, $winstate, $private) # This script launches Internet explorer with a specified or default URL and forces the browser window state (normal, maximized, Minimzed, Hidden) # main code starts here # check to see if a URL is specified and if not, set it to a default (http://www.microsoft.com/enterprise) if (-not $url) { $url = "http://www.microsoft.com/enterprise" } # check to see if a state has been specified and if not, set it to a default (Normal) if (-not $winstate) { $winstate = "Normal" } if ($private -eq "private") { $private = "-" + $private + " " } else { $private = " " } $appargs = $private + $url $appname = "C:\Program Files\Internet Explorer\iexplore.exe" # start the app $app = Start-Process $appname -ArgumentList $appargs -WindowStyle $winstate -passthru #need to wait for the process to start start-sleep 1 $WinStateInt = $winstate switch ($WinStateInt) { "Hidden" {$WinStateInt = 0} "Normal" {$WinStateInt = 1} "ShowMinimized" {$WinStateInt = 2} "Maximized" {$WinStateInt = 3} "ShowNoActivate" {$WinStateInt = 4} "Show" {$WinStateInt = 5} "Minimized" {$WinStateInt = 6} "ShowMinNoActive" {$WinStateInt = 7} "ShowNA" {$WinStateInt = 8} "Restore" {$WinStateInt = 9} "ShowDefault" {$WinStateInt = 10} "ForceMinimize" {$WinStateInt = 11} } $sig = '[DllImport("user32.dll")] public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);' Add-Type -MemberDefinition $sig -name NativeMethods -namespace Win32 [Win32.NativeMethods]::ShowWindowAsync($app.MainWindowHandle, $WinstateInt)