Tags » Scripting

PowerShell: Export-CmReports.ps1

Another I glued together today for a lab project.  No error trapping, weeeee!

 Export-CmReports exports SCCM SQL RSP reports to RDL files in
 a specified location

 3-character site code

 NetBios hostname of SCCM RSP host

.PARAMETER ReportFolder
 Name of logical SSRS report folder, or "ALL" to export all folders
 Default is "/" which is not recursive

.PARAMETER OutputFolder
 Path location where RDL files will be exported
 Default is $USERPROFILE\Documents

 Written by: David Stein
 Date Create: 10/19/2016

 Export-CmReports -SiteCode "ABC" -HostName "CM1"
 Export-CmReports -SiteCode "ABC" -HostName "CM1" -ReportFolder "My Custom Reports" -OutputFolder "C:\Temp"
 Export-CmReports -SiteCode "ABC" -HostName "CM1" -ReportFolder "ALL" -OutputFolder "C:\Temp"

function Export-CmReports {
  param (
      $ReportFolder = "/",
      $OutputFolder = "$($env:USERPROFILE)\Documents"
  $url = "http://$HostName/ReportServer/ReportService2010.asmx?WSDL"
  Write-Host "connecting to SSRS web service..." -ForegroundColor Cyan
  $ssrs = New-WebServiceProxy -Uri $url -UseDefaultCredential -Namespace "ReportingWebService"
  if ($ReportFolder -eq "ALL") {
    $folders = $ssrs.ListChildren("/ConfigMgr_$SiteCode", $False) | ?{$_.TypeName -eq 'Folder'}
  else {
    $folders = $ssrs.ListChildren("/ConfigMgr_$SiteCode", $False) | ?{$_.Name -eq "$ReportFolder"}

  if ($folders.Length -gt 0) {
    foreach ($folder in $folders) {
      $fname = $folder.Name
      $fpath = $folder.Path
      $reports = $ssrs.ListChildren("$fPath" , $False)
      if ($reports.Length -gt 0) {
        Write-Host "Folder: $fName : $($reports.Length) reports" -ForegroundColor Cyan
        $OutPath = "$OutputFolder\$fName"

        if (!(Test-Path $OutPath)) {
          md $OutPath -Force
        foreach ($r in $reports) {
          $reportName = $r.Name 
          if ($r.Hidden -eq $True) {
            Write-Host "skipping hidden report: $reportName" -ForegroundColor Gray
          else {
            Write-Host "reading: $reportName..." -ForegroundColor Green
            $def = $ssrs.GetItemDefinition($r.Path)
            $stream = ::OpenWrite("$OutPath\$reportName.rdl")
            $stream.Write($def, 0, $def.Length)
            Write-Host "exported: $reportName successfully!" -ForegroundColor Green
      else {
        Write-Host "no reports were found" -ForegroundColor Cyan
    } # foreach
  Write-Host "done!"
} 20 more words

PowerShell: Test-OnBatteryPower

I’ve tested this on two HP laptops and a Dell laptop. The Dell is on 1511, one HP is on 1607 and the other on Insider Build 14931.   19 more words


Scripting Language Idioms: The "Seen" Hash

The “seen” hash technique is an idiom that lets you use a hash (or dictionary if you prefer) as a set data type. It’s good for generating a de-duplicated list of things, where each thing appears only once. 767 more words


PowerShell iCacls

Disclaimer:  Written without coffee, while dog was barking in the next room, and cat was clawing my leg.  I needed this for a small project and it seems to work as intended.   293 more words


PowerShell Remoting Kerberos Double Hop Solved Securely – GoateePFE

The struggle is real.

by Ashley McGlone / TechNet Blogs

Are you facing issues with PowerShell remoting and credentials? You remote into your jump box, but then any remoting beyond there gets a big red ACCESS DENIED. 43 more words


Turn SCCM SQL Queries into Web Reports

The goal of this exercise is to add custom reports to your Configuration Manager site so you can dazzle executives while you sneak out the door.   1,473 more words


PowerShell - Is Local Admins Group Member

crude / but effective…

function Test-LocalAdminsGroupMember {
  param (
  $x = $(NET LOCALGROUP Administrators)
  $members = $x
} 6 more words