Solved

PowerShell - retrieve credential

Posted on 2015-01-26
2
99 Views
Last Modified: 2015-01-26
Hi,

I have the powershell below that prompt me for my credential once, then run / export SCCM report which work great for me but for my colleague, he is prompt twice before that export start.

I do not see where my mistake is, can you help?


function get-Report([String] $reportID, [String] $destination)
{
  $url = "http://xx.x.xx.xx/SMSReporting_CS1/Report.asp?ReportID=$reportID"

  #Start XML
  $xhttp = new-object -com msxml2.xmlhttp
  $xhttp.open("Post",$url,$false,$Cred)
  $xhttp.setrequestheader("Content-Type","application/x-www-form-urlencoded")

  #this sends the request to perform a CSV export
  $xhttp.send("export=yes")

  #This line's not needed but I use it to get confirmation
  #that the download is queued correctly.  If not OK then
  #I know to check the above part of this script
  Write-Host "$url - result: $($xhttp.statustext)"

  #Now grab the file in the buffer and save it to disk
  $stream = new-object -com ADODB.Stream
  $stream.open()
  $stream.type = 1

  #Connect the buffer to the downloaded file
  $stream.write($xhttp.responsebody)
  $stream.savetofile($destination,2)
  $stream.close()
  $stream = $nul

}

$Cred = get-credential

get-SCCMReport 774 "\\pick01\Doc\Dev\HC001.csv"
get-SCCMReport 779 "\\pick01\Doc\Dev\HC002.csv"
get-SCCMReport 776 "\\pick01\Doc\Dev\HC003.csv"

Open in new window

0
Comment
Question by:mldaigle1
2 Comments
 
LVL 7

Accepted Solution

by:
Network Zero earned 500 total points
ID: 40570765
Have him try and run it as Admin
0
 

Author Closing Comment

by:mldaigle1
ID: 40571000
This is it!  That's the problem!

Thanks alot Network Zero

Have a great day! :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
A brief introduction to what I consider to be the best editor for PowerShell.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now