Can anyone please tell me how to click on \"ok\" or \"cancel\" on a popup window using powershell? I am trying to automate a website using powershell, but I am new to powershell
With Powershell v2 you can use PInvoke to access the normal Win32 API, thus giving you access to FindWindow and SetForegroundWindow.  Then use SendKeys to send a Enter key.
Something like this to register the methods:
$pinvokes = @'
    [DllImport("user32.dll", CharSet=CharSet.Auto)]
    public static extern IntPtr FindWindow(string className, string windowName);
    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    public static extern bool SetForegroundWindow(IntPtr hWnd);
'@
Add-Type -AssemblyName System.Windows.Forms
Add-Type -MemberDefinition $pinvokes -Name NativeMethods -Namespace MyUtils
Now you can find the window you need:
$hwnd = [MyUtils.NativeMethods]::FindWindow(null, "Popupboxname")
Give it focus:
[MyUtils.NativeMethods]::SetForegroundWindow($hwnd)
And send the Enter key:
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
Sources/inspiration: