none
getting/setting share permissions RRS feed

  • Question

  • I am working wiht getting share permisisons from one location, and applything them to a new share at a 2nd location. I can't seem to get any good examples on the SET-ACL cmdlet though. Can anyone offern any guidance, or a better way to do this? Thanks!

    cls
    $arrayNewAccess = @()
    #http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/c98d4613-f9a2-4f44-b0db-93bb329ce225/
    
    #WMI class info
    #http://msdn.microsoft.com/en-us/library/aa394435(v=VS.85).aspx
    
    #displays shares
    #Get-WmiObject -Class Win32_Share -ComputerName localhost
    
    #use the get-ACL cmdlet to get permissions of source
    $result = Get-Acl c:\test2
    foreach ($item in $result)
    {
    	foreach ($access in $item.Access)
    	{
    		#lists who has access to share in format "<domain>\<group or person>"
    		#$access.IdentityReference
    		$arrayNewAccess += $access.IdentityReference
    	}
    }
    
    $arrayNewAccess
    
    #create new share, 0 is type of share (disk drive) 100 is max num of people in it
    (Get-WmiObject -List -ComputerName localhost | Where-Object -FilterScript {$_.Name -eq "Win32_Share"}).InvokeMethod("Create",("C:\test3","test3",0,100,"Share description")) 
    
    #set access to new share
    foreach ($element in $arrayNewAccess)
    {
    	Set-Acl c:\test3
    }
    

     

    Tuesday, August 2, 2011 7:06 PM

Answers

  • 1) You may use Share module by Vadims Podans - http://en-us.sysadmins.lv/psscripts/ShareUtils.zip.

     

     

    PS > Import-Module ShareUtils
    PS > Get-Command -Module ShareUtils
    
    CommandType  Name            Definition
    -----------  ----            ----------
    Filter   Add-SharePermission         ...
    Function  Get-Share           ...
    Function  New-Share           ...
    Filter   Remove-Share          ...
    Filter   Remove-SharePermission        ...
    Filter   Set-Share           ...
    Filter   Set-SharePermission         ...
    Function  Test-ElevatedShell         ...
    
    


    2) http://archive.msdn.microsoft.com/bsonposh

    PS > Get-Command -Module BSShare
    
    CommandType   Name                        Definition
    -----------   ----                        ----------
    Function    Add-SharePermission                 param($user, $AceType, $AccessMask)...
    Function    ConvertFrom-ShareReturnCode             param($write)...
    Function    Get-Share                      ...
    Function    New-Share                      ...
    Function    New-ShareObject                   ...
    Function    Remove-Share                    ...
    Function    Remove-SharePermission               param($user)...
    Function    Set-Share                      ...
    Function    Set-SharePermission                 ...


     


    • Marked as answer by Robert Little Wednesday, August 3, 2011 2:00 PM
    Tuesday, August 2, 2011 7:25 PM

All replies

  • 1) You may use Share module by Vadims Podans - http://en-us.sysadmins.lv/psscripts/ShareUtils.zip.

     

     

    PS > Import-Module ShareUtils
    PS > Get-Command -Module ShareUtils
    
    CommandType  Name            Definition
    -----------  ----            ----------
    Filter   Add-SharePermission         ...
    Function  Get-Share           ...
    Function  New-Share           ...
    Filter   Remove-Share          ...
    Filter   Remove-SharePermission        ...
    Filter   Set-Share           ...
    Filter   Set-SharePermission         ...
    Function  Test-ElevatedShell         ...
    
    


    2) http://archive.msdn.microsoft.com/bsonposh

    PS > Get-Command -Module BSShare
    
    CommandType   Name                        Definition
    -----------   ----                        ----------
    Function    Add-SharePermission                 param($user, $AceType, $AccessMask)...
    Function    ConvertFrom-ShareReturnCode             param($write)...
    Function    Get-Share                      ...
    Function    New-Share                      ...
    Function    New-ShareObject                   ...
    Function    Remove-Share                    ...
    Function    Remove-SharePermission               param($user)...
    Function    Set-Share                      ...
    Function    Set-SharePermission                 ...


     


    • Marked as answer by Robert Little Wednesday, August 3, 2011 2:00 PM
    Tuesday, August 2, 2011 7:25 PM
  • let me take a step back from the permissoin thing kazun. I am trying to copy files and folders from one (network) location to another while keeping permissions intact. Copy-Item doesn't seem to do that Maybe I am just using it wrong? No need to go all crazy with permissions if I can just copy my files from source to target and keep permissions intact right?

    copy-item -Path c:\test2 -Destination c:\test3 -Recurse

     




    edit: going to make a new thread, you can still reply here if you'd like. your response from yesterdya is still good information
    Wednesday, August 3, 2011 1:58 PM