none
Parsing Icacls results RRS feed

  • Question

  • Hello!

    Basically I want a conditional statement, if icacls failed processing any files, then do not continue. Please imagine you are writing a PowerShell script, this script runs $icaclsResult = Icacls.exe $soruce, where $source is a valid folder path. 

    So now we have the output of the Icacls run inside the variable $icaclsResult. A typical icacls runs last line typically looks as follows :

    Successfully processed 12 files; Failed processing 0 files

    Is it possible for me to parse the entire icacls result so that I can use the number following Failed processing as a sort-of exitcode?

    Thank you in advance.

    Friday, January 31, 2014 8:45 PM

Answers

  • This will work until something else better comes along.

    $Source = 'C:\Windows'
    $Icacls = (icacls $Source | findstr /i 'processing').split(' ')[-2]


    • Edited by tommymaynard Friday, January 31, 2014 9:08 PM
    • Marked as answer by Joster422 Monday, February 3, 2014 7:50 PM
    Friday, January 31, 2014 9:06 PM

All replies

  • This will work until something else better comes along.

    $Source = 'C:\Windows'
    $Icacls = (icacls $Source | findstr /i 'processing').split(' ')[-2]


    • Edited by tommymaynard Friday, January 31, 2014 9:08 PM
    • Marked as answer by Joster422 Monday, February 3, 2014 7:50 PM
    Friday, January 31, 2014 9:06 PM
  • PS C:\scripts> icacls c:\windows\*.log /T|?{ $_ -match 'Successfully processed (?<success>\d+)(?<failed>\d+)'}
    Successfully processed 111 files; Failed processing 1 files
    PS C:\scripts> $matches['success']
    11
    PS C:\scripts> $matches['failed']
    1
    PS C:\scripts>


    ¯\_(ツ)_/¯


    • Edited by jrv Friday, January 31, 2014 9:35 PM
    Friday, January 31, 2014 9:33 PM
  • This is also useful:
    icacls c:\windows\*.log /T 2>errors.txt

    the errors will be in the error log.


    ¯\_(ツ)_/¯

    Friday, January 31, 2014 9:37 PM