Solved

PowerShell - retrieve credential

Posted on 2015-01-26
2
98 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
Comment Utility
Have him try and run it as Admin
0
 

Author Closing Comment

by:mldaigle1
Comment Utility
This is it!  That's the problem!

Thanks alot Network Zero

Have a great day! :)
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
Synchronize a new Active Directory domain with an existing Office 365 tenant
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

763 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

9 Experts available now in Live!

Get 1:1 Help Now