Benutzer-Werkzeuge

Webseiten-Werkzeuge


programmierung:powershell

Some common tasks in Windows PowerShell

  • suppress output of Cmdlets (e.g. new-item): pipe to out-null
  • suppress error output of binaries: svn log 2> $null
  • suppress error messages (even those that won't go away with -ea 0): $ErrorActionPreference = "silentlycontinue"
  • check if an error occured (e.g. after cmdlet with suppressed output): if (!$?)
  • copy-item throws an UnauthorizedAccessException: use parameter -force
  • RegEx:
    $m = [regex]::matches("test", "([a-z]+)");
    if ($m[0].Success)
    {
      $str = $m[0].Groups[1].ToString();
    }
  • get name and path of the currently running script:
    $scriptName = $MyInvocation.MyCommand.Name;
    $scriptPath = split-path $MyInvocation.MyCommand.Path;
programmierung/powershell.txt · Zuletzt geändert: 2014-04-05 11:42 (Externe Bearbeitung)