Solved

PowerShell - retrieve credential

Posted on 2015-01-26
2
102 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
This article will help you understand what HashTables are and how to use them in PowerShell.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

776 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