header1   header
header
header : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
IMPORTANT: PowerShellCommunity.org is moving! - Wednesday, August 15, 2012

PowerShellCommunity.org is moving!  This community software, and the hardware that it sits on, are no longer serving the purposes of this community.  As a result, we have decided to move this community to a new home at PowerShell.org.  PowerShell.org is already up and running with the new community software and in its new location, so please post any new questions that you have on the forums over there instead of posting them on this site.  We've already started getting some great questions from members of the community over there so please, come on over and join us!

While we are going through this transition, this site will remain up for the short term.  New posts may no longer be created on these forums, however replies to existing posts are allowed so that users who posted questions don't have to re-post the same question on the new site.

[UPDATE 28/02/2013] New user registration has been disabled and forums have now been switched to read-only, including for existing posts since all threads that were started should now be completed. If you have a question about content on this site or about PowerShell in general, head over to PowerShell.org and ask it there where there are people actively using the site and answering questions.

If you have any questions, please let us know on the PowerShell.org site.

Thank you,

Kirk "Poshoholic" Munro

 
Get Directory Permissions
Last Post 10 Jul 2012 08:11 PM by ChevyNovaLN. 1 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Not Resolved
Eat12User is Offline
New Member
New Member
Posts:1
Avatar

--
09 Jul 2012 05:54 AM
    Hello,

    Currently I am trying to get the cacls permissions assigned to a folder directory of the database data files.  I can get the list of directories now I am stuck on feeding each line into a loop as I am a complete newbie.

    [String] $inventoryinstance="Server\Instance"
    [String] $inventorydatabase="Database"

    $smoAssembly = [reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo")
    if (!($smoVersion))
    { Set-Variable -name SmoVersion -value $smoAssembly.GetName().Version.Major -Scope Global -Option Constant

    -Description "SQLPSX variable" }
    [reflection.assembly]::LoadWithPartialName('Microsoft.SqlServer.SMOExtended') > $null

    #Get-DataFilePath
    function Get-DataFilePathList
    {
    $instance = New-Object ('Microsoft.SQLServer.Management.SMO.Server') $inventoryinstance
    $database = $instance.Databases[$inventorydatabase]
    #Param ($database)
    $result=$database.ExecuteWithResults("SELECT InstanceName, DBName, DataFilePath from dbo.tblDatabases")
    $result.Tables | foreach {$_.Rows}
    }

    Get-DataFilePathList | foreach {$_.DataFilePath | Write-Output}

    The output from this is the data file directories:

    D:\MSSQL10.DEV806MSSQL\MSSQL\DATA\master.mdf
    D:\MSSQL10.DEV806MSSQL\MSSQL\DATA\tempdb.mdf
    D:\MSSQL10.DEV806MSSQL\MSSQL\DATA\model.mdf
    D:\MSSQL10.DEV806MSSQL\MSSQL\DATA\MSDBData.mdf
    D:\MSSQL10.DEV806MSSQL\MSSQL\Data\DBA_Maint.mdf

    What's the best way to feed the output from this; $_.DataFilePath into a Foreach loop to get the permissions. (cacls/Get-Acl) Thanks in advance for the response.
    ChevyNovaLNUser is Offline
    Basic Member
    Basic Member
    Posts:135
    Avatar

    --
    10 Jul 2012 08:11 PM
    You could do something like this. The code below works for folders or files, though its relying on your function to return some sort of path to 'something' whether that be a folder or file name.

    
    $DBFiles = Get-DataFilePathList 
    foreach ($DBFile in $DBFiles)
    {
    $FileName = $DBFile.DataFilePath
    "FILE:    $FileName"
    "**********************"
    (Get-Acl $DBFile.DataFilePath).Access | select IdentityReference,FileSystemRights | Write-Output
    }
    
     
    Brian / ChevyNovaLN
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Many thanks to our original sponsors: Quest Software • SAPIEN Technologies • Compellent • Microsoft footer
    footer   footer