header1   header
header
header : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
IMPORTANT: PowerShellCommunity.org is moving! - Wednesday, August 15, 2012

PowerShellCommunity.org is moving!  This community software, and the hardware that it sits on, are no longer serving the purposes of this community.  As a result, we have decided to move this community to a new home at PowerShell.org.  PowerShell.org is already up and running with the new community software and in its new location, so please post any new questions that you have on the forums over there instead of posting them on this site.  We've already started getting some great questions from members of the community over there so please, come on over and join us!

While we are going through this transition, this site will remain up for the short term.  New posts may no longer be created on these forums, however replies to existing posts are allowed so that users who posted questions don't have to re-post the same question on the new site.

[UPDATE 28/02/2013] New user registration has been disabled and forums have now been switched to read-only, including for existing posts since all threads that were started should now be completed. If you have a question about content on this site or about PowerShell in general, head over to PowerShell.org and ask it there where there are people actively using the site and answering questions.

If you have any questions, please let us know on the PowerShell.org site.

Thank you,

Kirk "Poshoholic" Munro

 
Control IE to download CSV problem
Last Post 23 Apr 2012 10:39 AM by sylvainm. 0 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
sylvainmUser is Offline
New Member
New Member
Posts:1
Avatar

--
23 Apr 2012 10:39 AM
    I'm trying to write a powershell script that controls IE to connect to a secure web interface for OPSware that let's me export all the data to a CSV file. I can't seem to create correct cookies and headers to use [System.Net.WebClient ] so that's why I've switched to controlling IE. I've figured out how to navigate and "click" thru what I need but for the last step to submit the export, all I get is a popup from IE 9 at the bottom to open or save the csv file. I can't figure out how to control that portion. Here's a sample of my script

    $username = $env:username
    # Change this to a location of your choosing
    $passwordfile = "C:\OpswareAuth_$($env:username).txt"
    # Function to return a password from an encrypted file
    Function get-password([string]$credentialsfile) { 
       if (-not (Test-Path $credentialsfile)){ 
          $creds = Get-Credential $env:username 
          $encpassword = $creds.password 
          $encpassword |ConvertFrom-SecureString |Set-Content $credentialsfile
       } else { 
          $encpassword = get-content $credentialsfile | convertto-securestring 
       }
       $ptr = [System.Runtime.InteropServices.Marshal]::SecureStringToCoTaskMemUnicode($encpassword) 
       $pass = [System.Runtime.InteropServices.Marshal]::PtrToStringUni($ptr)
       remove-variable encpassword,ptr
       return $pass
    }
     # Create the IE com object
    $ie = new-object -com InternetExplorer.Application
    $ie.visible = $true
    # Navigate to the login page
    $ie.navigate(https://gisops02)
    do {sleep 1} until (-not ($ie.Busy))
    $doc variable $doc = $ie.document
    if($ie.Document.title -match "Certificate Error") { 
       #Deal with bad certs 
       $OverRide = $doc.getelementbyid("overridelink") 
       $OverRide.click() 
    }
    do {sleep 1} until (-not ($ie.Busy))
    $doc = $ie.document
    # Our login page remembers credentials for an hour even after
    # closing a browser, so we're going to enclose the login part
    # in a try-catch block, as these fields may not exist if we've already run this.
    try { 
       $usernameField = $doc.getElementById('j_username') 
       $usernameField.value = $username 
       $passwordField = $doc.getElementById('j_password') 
       $passwordField.value = get-password $passwordfile 
       $doc.getElementById('bLogin') $submitButton.click() 
       # Wait until login is complete 
       do {sleep 1} until (-not ($ie.Busy))
    } catch {$null}
    # return servers under Managed Servers
    $ie.navigate("https://gisops02/com.opsware.occ.servers/index.jsp")
    do {sleep 1} until (-not ($ie.Busy))
    $ie.navigate("https://gisops02/com.opsware.occ.servers/menu/process?cmd=export&viewPref=s&i=0&sz=-1&groups=0&items=0&exportChoice=All")
    do {sleep 1} until (-not ($ie.Busy))
    $csvBody = $ie.document
    # here is where I get the popup that I can't control. I played around with ExecWB but it didn't seem to what I needed

    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Many thanks to our original sponsors: Quest Software • SAPIEN Technologies • Compellent • Microsoft footer
    footer   footer