Script Question - Share Permissions Listing on a List of Servers

Answered Script Question - Share Permissions Listing on a List of Servers

  • Wednesday, February 13, 2013 2:40 PM
     
      Has Code

    Also what adjustments need to be made to this script to list the same results of share permissions on the servers in the list.  Instead of whos a member of local admins I need a list of shares per server and who has access on those shares. 

    $servers=get-content 'servers.txt'
    $output='test.csv'
    $results=foreach($server in $servers){
    
         $group=[ADSI]"WinNT://$server/Administrators"
         $group.psbase.Invoke("Members") |
         ForEach-Object{
              new-object psobject -Property @{ 
                                              Server=$Server 
                                              Name=$_.GetType().InvokeMember("adspath", 'GetProperty', $null, $_, $null)
                                             } 
         }
    
    } 
    $results #| Export-Csv $output -NoType 


    • Edited by GovtTech Wednesday, February 13, 2013 3:53 PM
    •  

All Replies

  • Wednesday, February 13, 2013 3:41 PM
     
     

    "Script Question" is not a question or a very usable topic.  Topic are supposed explicitly reference the question or target issue. Can you please rename your topic to somethinguseful.

    There are numerous scripts in the repository that will return share permisisons and shares.  Take your pick.

    YOU post this with your question as if you are asking for someone to write teh script for you.  We do not write custom scripts on demand.  If someone has a script that is close they might post it.  Modification and customization are up to you.

    Always search the repository first.  It will save you a lot of time.

    http://social.technet.microsoft.com/Forums/en-US/ITCG/threads?announcementId=9b95bcaf-c128-4166-abf8-a521998a9d81

    http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/ff3f3b21-8ed5-47b0-bc30-5ca3bbe91029


    ¯\_(ツ)_/¯

  • Thursday, February 14, 2013 3:29 PM
     
     
    The other suggestions are kind of lame, share enum looks nice but when you export it, it gets all messed up and imported in to excel butchers it even more.  I'll seek elsewhere then.
  • Thursday, February 14, 2013 3:37 PM
     
     
    The other suggestions are kind of lame, share enum looks nice but when you export it, it gets all messed up and imported in to excel butchers it even more.  I'll seek elsewhere then.

    Yu are required to make your own modifications.  Start by using the Learnlink.  Output to Exceel takes one line of code. Export-Csv

    ¯\_(ツ)_/¯

  • Thursday, February 14, 2013 4:51 PM
     
     

    This look ok?

    $servers=get-content 'servers.txt'
    $output='test.csv'
    $results=foreach($server in $servers){

     

     

    $shares = Get-WmiObject Win32_Share -filter "type!=1" -ComputerName
    $ComputerName |  foreach { $_.getRelated
    ("Win32_LogicalShareSecuritySetting") }
    $shares | foreach { $_.GetSecurityDescriptor().descriptor.DACL } |
    select $Share,$AccessMask,$AceType,$Trustee


    }
    $results #| Export-Csv $output -NoType

  • Thursday, February 14, 2013 4:54 PM
     
     

    What is the question?  What is not working?

    Why did you comment out the results?


    ¯\_(ツ)_/¯

  • Thursday, February 14, 2013 4:59 PM
     
     
    No - it does not look even close to a usable script.  Why don't you use the examples that work.  There are at least two that I remember were in the repository.

    ¯\_(ツ)_/¯

  • Thursday, February 14, 2013 5:05 PM
     
     
    I pieced together the script you had above top and bottom section and in the middle included a script i found online that lists shares and permissions.
  • Thursday, February 14, 2013 5:16 PM
     
     

    OK I'm going to try http://gallery.technet.microsoft.com/scriptcenter/a231026a-3fdb-4190-9915-38d8cd827348

    To get it to export to a csv i just add "Export-Csv " at the very end yes?


  • Thursday, February 14, 2013 5:25 PM
     
     
    OK well I renamed that psm1 file to ps1 and ran it, it said only run scripts you trust so I hit R for run once and it went to the next line and nothing.  Sorry to be a noob. 
  • Thursday, February 14, 2013 5:57 PM
     
     Answered

    Start at the learn link on the above menu.

    YOu cannot jsut blindly glue scripts together without some understanding of what is happening.  YOu have all of the commands but they are not arraged so as to give you a clean result.

    Byt the way; shqare permissions are not what you see in the file system.  Look at the docs to see what share permisisons are and how they are used. 


    ¯\_(ツ)_/¯

  • Thursday, February 14, 2013 8:16 PM
     
     
    Kinda pressed for time, thanks anyway
  • Thursday, February 14, 2013 8:27 PM
    Moderator
     
     

    Hi,

    As noted previously, we don't really have the resources to write customized solutions for others for free. We're glad to help if you have a specific question, but it's beyond the scope of this forum to post a list of requirements and expect others to write a script for you.

    Bill

  • Thursday, February 14, 2013 9:36 PM
     
     
    I figured a script to show a list of all the shares and permissions of shuch shares on all servers in a domain would have been a common script but alas there is none in the repository.  I guess others have lax auditors.
  • Thursday, February 14, 2013 9:46 PM
     
     
    Kinda pressed for time, thanks anyway

    Part of th e issue is that you do not have any skills in POwerShell or in scripting so anything we show you becomes a new question.

    The link to the module (FileSharePermissions.psm1) gives you a script that does exactly what you asked for assuming your know how to run an Advanced CmdLet in PowerShell.

    Just add teh file to your modules folder and load it and you are set and have extended PowerSHell to get sharte permisisons.  Boe Prox (the author) is an excellent programmer and WIndows systems person.  He has produced many near perfect extensions to PowerSHell .  You cannot do much better.

    YOU said you altered his code but you shouldn't have since you do not understand PowerShell.  The way you modified it will not work unless you dort soure the load.  YOu also need to be sure the security on PowerShell is set up correctly.

    Start with the learn menu item and review the basics of setting up PowewrShell to execute scripts.

    Load the module acording to Boe Prox's instuctions and follow his usage help that is built in.  YOu will get the share permissions.

    To be certain I jsut loaded and tested this and it works perfectly.  Be sure you are running as an administrator,

    By the way. All of this took less thatn 2 minutes while I was on the phone and fixing another issue.

    Use Import-Module <modulename>

    Store teh script in a folder in teh modules directory with teh same name minus the extension.


    ¯\_(ツ)_/¯


  • Thursday, February 14, 2013 9:47 PM
     
      Has Code

    Examples:

    16:44 PS>import-module FileSharePermissions
    16:44 PS>Get-SharePermissions omega2
    Computer   : omega2
    Name       : print$
    ID         : Everyone
    AccessMask : ReadAndExecute
    AceType    : Allow
    Computer   : omega2
    Name       : print$
    ID         : Administrators
    AccessMask : FullControl
    AceType    : Allow
    Computer   : omega2
    Name       : print$
    ID         : Power Users
    AccessMask : FullControl
    AceType    : Allow
    Computer   : omega2
    Name       : print$
    ID         : Power Users
    AccessMask : FullControl
    AceType    : Allow


    ¯\_(ツ)_/¯

  • Thursday, February 14, 2013 10:18 PM
     
     
    I figured a script to show a list of all the shares and permissions of shuch shares on all servers in a domain would have been a common script but alas there is none in the repository.  I guess others have lax auditors.

    The script I jsut posted about does exactly what you asked.  I just ran it and posted the results.  There is no other way to do it.


    ¯\_(ツ)_/¯

  • Friday, February 15, 2013 1:09 PM
     
     
    You recommend going through all the videos under learn to start with?  parts 1-5?
  • Friday, February 15, 2013 1:18 PM
     
     
    You recommend going through all the videos under learn to start with?  parts 1-5?

    That is definiely a good place to start.

    ¯\_(ツ)_/¯