Tags » Scripting

Common awk tasks

1. Give names to each peak in a 3-column bed file:

$ cat Oct4_union_peaks.bed

chr1 3062833 3063056
chr1 3343519 3343843
chr1 3482630 3483324
chr1 3549654 3549895
chr1 3648929 3649295

$ awk 'BEGIN{OFS="\t"}{print $1,$2,$3,"Oct4_union_peak_" NR}' Oct4_union_peaks.bed

chr1 3062833 3063056 Oct4_union_peak_1
chr1 3343519 3343843 Oct4_union_peak_2
chr1 3482630 3483324 Oct4_union_peak_3
chr1 3549654 3549895 Oct4_union_peak_4
chr1 3648929 3649295 Oct4_union_peak_5

… 257 more words

User Rights in Server 2012

Rights are authorized action a user can perform on the system. They are tightly coupled with permissions which are applied at object level. These user rights can be applied through local policies or centralized group 798 more words


Documenting the NSX-v DFW with PowerNSX

Documenting firewall configuration is challenging at the best of times, in most enterprise networks there are tens of thousands of lines of ACLs that have been added organically over time to any number of firewalls. 313 more words


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

Merging multiple commands and piping it to one output.

The unix shell is hard, but boy, sometimes it can work like magic, for instance piping two testssl.sh commands into one gist:

retinambpro1tb:testssl.sh jeroenp$ ( ./testssl.sh --version ; ./testssl.sh --local ) | gist -d "testsll version and local ciphers for Mac OS X Darwin binarries supporting zlib"

43 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


Writing a script for the first time

I had a solid concept for my film, interviewing my past selves as my current self and now it was time to work on a mood board, narrative and script, I started the mood board (Image below) and worked from there, creating a narrative which I would flesh out later and started working on a script, I hadn’t wrote one before but once I worked out Celtx I started writing, I hit some formatting speed bumps on the way and was asked to remove/add some things at the end of the process but overall I am happy with it and feel I can follow it to make a short film I am happy with.