top of page

Windows PowerShell

Windows PowerShell is a command-line based application that comes with modern installations of the Windows operating system. It provides a framework for powerful automation of processes such as data management and QA/QC.

​

We are providing a few example code snippets for running simple but highly useful, time-saving QA/QC checks for common types of acoustic data.

 

To run the code, open Windows PowerShell, change to the directory which contains your data, and paste the full code snippet. If your data are on a drive other than C:, you will first need to type the drive letter followed by a colon (e.g., D:) and press enter. Next, type the following line, replacing the path with the path to your data:

cd "D:\data\2023\0 raw\3537\NW1"

Code Snippets

Copy the code below next to your acoustic data type to run simple QA/QC checks on your data. These snippets will search for detector serial numbers in the acoustic files and report all unique numbers found. If acoustic data from multiple detectors were accidentally placed in the same folder, the code below should reveal this error.

AnaBat ZC Data

$AcFiles = Get-ChildItem ".\*.*" -Recurse | Where-Object{$_.Extension -match '\.(?:zc|\d{2}#)'}
$found_sns = @()
""
foreach ($acf in $ACFiles){
  Write-Progress -PercentComplete ($AcFiles.IndexOf($acf) / ($AcFiles.Count - 1) * 100) -Activity "Scanning for unique serial numbers in files..." -Status "Processing item $($AcFiles.IndexOf($acf)) of $($AcFiles.Count - 1)"
  $acf_sn = Select-String -Path $acf -Pattern '(?:Serial:|SN\s*)(\d{4,})' | % {$_.matches.groups[1].value}
  if ($found_sns.Count -eq 0 -OR -NOT $found_sns.Contains($acf_sn) -AND $acf_sn.Length -gt 0){
     $found_sns += $acf_sn
     $found_sns.Count.ToString() + ': ' + $acf_sn
  }
}
"Done. Found " + $found_sns.Count.ToString() + " total SNs (see above).
"

Wildlife Acoustics WAV Data

$AcFiles = Get-ChildItem ".\*.wav" -Recurse
$found_sns = @()
""
foreach ($acf in $ACFiles){
  Write-Progress -PercentComplete ($AcFiles.IndexOf($acf) / ($AcFiles.Count - 1) * 100) -Activity "Scanning for unique serial numbers in files..." -Status "Processing item $($AcFiles.IndexOf($acf)) of $($AcFiles.Count - 1)"
  $acf_sn = Select-String -Path $acf -Pattern '((?:S\dU|SM\d)\d{4,})' | % {$_.matches.groups[1].value}
  if ($found_sns.Count -eq 0 -OR -NOT $found_sns.Contains($acf_sn) -AND $acf_sn.Length -gt 0){
     $found_sns += $acf_sn
     $found_sns.Count.ToString() + ': ' + $acf_sn
  }
}
"Done. Found " + $found_sns.Count.ToString() + " total SNs (see above).
"

bottom of page