none
NTFS Export RRS feed

  • Question

  • Hi experts,

    I am trying to export NTFS permissions for a bunch of servers, but I'm struggling with the last part of the script (especially the BOLDED part)

    } | select Principal,Rights,AceFlags,AceType Sort-Object ShareName -Wrap  | Export-CSV result.csv

    I'm using select to select all the columns I need the CSV file to show however I'm not sure how to group the results by ShareName. I've tried using Sort-Object but getting this error.

    Select-Object : A positional parameter cannot be found that accepts argument 'Sort-Object'.
    At line:21 char:5
    + } | select Principal,Rights,AceFlags,AceType Sort-Object ShareName -Wrap  | Expo ...
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [Select-Object], ParameterBindingException
        + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SelectObjectCommand

    Note that if I remove Sort-Object ShareName -wrap entirely from the script, it will run successfully and produce the CSV file, however, it will list permissions from ALL shares without grouping by Share.  

    Can someone PLEASE point me in the right direction, which CMDLET can I use to accomplish this task?

    Thank you!

    Original script below:

    Function Get-NtfsRights($name,$path,$comp)
    {
    	$path = [regex]::Escape($path)
    	$share = "\\$comp\$name"
    	$wmi = gwmi Win32_LogicalFileSecuritySetting -filter "path='$path'" -ComputerName $comp
    	$wmi.GetSecurityDescriptor().Descriptor.DACL | where {$_.AccessMask -as [Security.AccessControl.FileSystemRights]} |select `
    				@{name="Principal";Expression={"{0}\{1}" -f $_.Trustee.Domain,$_.Trustee.name}},
    				@{name="Rights";Expression={[Security.AccessControl.FileSystemRights] $_.AccessMask }},
    				@{name="AceFlags";Expression={[Security.AccessControl.AceFlags] $_.AceFlags }},
    				@{name="AceType";Expression={[Security.AccessControl.AceType] $_.AceType }},
    				@{name="ShareName";Expression={$share}}
    }
    
    gc serverlist.txt | foreach {
    	if ($shares = Get-WmiObject Win32_Share -ComputerName $_ | Where {$_.Path})
    	{
    		$shares | Foreach { Write-Progress -Status "Get share information on $($_.__Server)" $_.Name
    			Get-NtfsRights $_.Name $_.Path $_.__Server}
    	}
    	else {"Failed to get share information from {0}." -f $($_.ToUpper())}
    } | select Principal,Rights,AceFlags,AceType Sort-Object ShareName -Wrap  | Export-CSV result.csv


    • Moved by Bill_Stewart Thursday, January 3, 2019 3:58 PM This is not "debug/fix/rewrite my script for me" forum
    Friday, November 2, 2018 2:07 AM

All replies

  • You missed one pipe directly in front of the Sort-Object.

    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Friday, November 2, 2018 7:28 AM
  • You missed one pipe directly in front of the Sort-Object.

    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Thanks for pointing that out! The script did run after adding the pipe; however, it still produces a list of permissions without grouping by shares. Any idea how I can change the export function to go do a GroupBy or similar by 'ShareName'? Thanks again!




    • Edited by NeluC Friday, November 2, 2018 1:36 PM
    Friday, November 2, 2018 1:23 PM
  • Did you read your one post after you posted it? Please fix it - it is unreadable.

    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Friday, November 2, 2018 1:30 PM
  • Did you read your one post after you posted it? Please fix it - it is unreadable.

    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Fixed, it was my stupid Grammarly Chrome add-on
    Friday, November 2, 2018 1:37 PM
  • How exactly do you imagine the results will look like after they have been grouped? The answer to this might require you taking a different approach to your script, because as far as I can see from the current iteration of your script it makes most sense when you DO include all shares, which makes the select statement in your last line unnecessary (anything you haven't included in this second select will not be visible to the remainder of the pipeline, including whatever grouping method you are imagining).

    Monday, November 5, 2018 9:19 AM