How to Unlock all folders and Files in One Main Folder

How do i unlock all files and folders in one main folder? This way I wouldn't have to do it over 1,000 times to fix my folders I imported from my external drive.

Open the Script Editor in the /Applications/AppleScript/ folder and enter the following:
tell application "Finder"
set locked of every item of entire contents of (selection as alias) to false
end tell
Select the main folder in the Finder and run the script.
(39015)

Similar Messages

  • How can I restore folders and files from Previous Systems folder

    I have been unable to migrate files (or even find the option to migrate files) located in my Previous Systems folder. I've been able to change the Privilege of these files to Read & Write (though my Permissions still indicate "You can only read.") and drag them from my previous Users folder to my current desktop, which creates a situation where I have them but am still unable to alter them (or delete them).
    thanks, all.

    Here's my exact issue: I've spent many hours converting vinyl records to mp3s, which were then stored in the iTunes folder of my previous system. Upon performing the Archive and Install, all of these files were located in my Previous Systems>Users>"X">Music folder, which initially could not be opened, prompting the notice, "The folder Music could not be opened because you do not have sufficient access privileges." So, I clicked "Get Info" and changed the Privilege from Read Only to Read & Write. From there I could open the folder, and as you pointed out, move these files wherever I chose. The problem is that I can't use them in any practical sense; I can't import them to my iTunes library and I can't delete them, being notified, "The operation can't be completed because backup items can't be modified." Which, would lead me to believe that I have yet to restore them properly.

  • How to link another forms and reports in one main forms?

    hai all,
    how to link another forms and reports in one main forms?
    i am creating Custom forms Main_menu
    in that i am puting on button and
    pl/sql code for when-button-pressed
    BEGIN
    Open_form('GROUP_MSTR_ENTRY');
    END;
    i am getting:
    ERROR:frm-40010: cannot read form GROUP_MSTR_ENTRY
    also i am un able change the text colour in form.
    how to link reports in forms?
    any help?
    before open i have to link all form i need?
    thanks in advance
    rcs
    ------

    even after changing to The forms_path variable and
    put the executable(GROUP_MSTR_ENTRY.fmx
    F:\oracle\ora90\FORMS60\server\FACCT\MAIN_MENU\GROUP_MSTR_ENTRY.FMX
    not working
    also i am un able change the text colour in form. how?
    how i can find?
    $ORACLE_HOME/forms/server/default.env
    my files are
    9i oracle database
    SQL*Plus: Release 9.0.1.0.1 - Production on Fri Dec 19 11:37:07 2008
    E:\oracle\ora90\bin\oemapp.batt
    forms6i
    F:\oracle\ora901\bin\
    since 9i is later than forms 6i i am unable to put in the same directory
    ------------

  • How to recover lost folders and files - Pls help, help...

    Some days ago I lost all of my 15 GB folders and files that stored in my Macbook Pro hard drive called DATA.  I brought my Macbook pro to an experienced computer tecnicians who providing data recovery services. To his and my suprise, after checking, scanning it a few hours, he said their is no way to recover because he did not find any trails at all.  The computer still seems working properly - I have no problem with any applications.  There are few other folders in the DATA hard disk containing pictures, computer programs still remain.  These lost folders and files contain mainly documents (word, excel, power point, pdf etc) which I accumulated in my many years working  !!!!.  I did not make a back up since last September partly because I think Mac is very safe.
    The computer with me all the time on that day and only my son used Power Point to make a simple presentation on that evening - he can not save it on the folders the he normally use - All the folders and files are gone.
    I will appreciate it very much if any of you can tell me what would be the possible causes and more importanly how to recover the lost folders and files.  They are very very valuable to me.
    Many thanks for your kind attention
    Loimekong from Vietnam
    Macbook Pro 2.4 Ghz
    Intel Core 2 Duo
    4 GB 1067 MhZ DDR3

    First, did the data actually get deleted, or is it still there somewhere?  Try searching the drive for some of the documents, perhaps it's all just in another folder on that drive.
    If it's truly gone, it's impossible for us to say what might have happened to make it unrecoverable.  Perhaps someone using the computer used Secure Empty Trash, or securely erased empty space on the hard drive.  Perhaps it was overwritten by other stuff before you noticed.  It's possible the hard drive is starting to fail, though this seems like an awfully specific problem for that to be the issue.
    Or perhaps the tech you took the computer to didn't know what he was doing.  Why not try recovering what you can on your own?  See Recovering deleted files.
    You should be aware that no computer is safe.  All computers rely on hardware that may fail and software that can have bugs.  You absolutely MUST maintain a good set of frequently-updated backups...  no fewer than two full backups of anything you don't want to lose.
    (Note that my pages contain links to other pages that promote my services, and this should not be taken as an endorsement of my services by Apple.)

  • How get SharePoint Library Folders and Files directory structure in to my custom web site.

    Hi,
    Actually my requirement is, I would like to pass site name and document library name as a parameter and get a folders and files from the document library and form the directory structure by using Treeview control in my web site.
    How should i get? Using Web service / object model?
    Web service would return the dataset as a result so from that how could i form the directory structure using Treeview control.
    I will select specified files and folders then i ll update sharepoint document library columns for corresponding selected files.
    Can anyone help over this, that would be great appreciate.
    Thanks in Advance.
    Poomani Sankaran

    Hello,
    Here is the code to iterate through sites and lists:
    //iterate through sites and lists
    SPSecurity.RunWithElevatedPrivileges(delegate()
    using (SPSite site = new SPSite(webUrl)) {
    using (SPWeb oWebsite = site.OpenWeb())
    SPListCollection collList = oWebsite.Lists;
    foreach (SPList oList in collList)
    {//your code goes here }
    Then use RecursiveAll to get all files and folders.
    http://www.codeproject.com/Articles/116138/Programatically-Copy-and-Check-In-a-Full-Directory
    http://sharepoint.stackexchange.com/questions/48959/get-all-documents-from-a-sharepoint-document-library
    Here is the full code:
    http://antoniolanaro.blogspot.in/2011/04/show-document-library-hierarchy-in-tree.html
    Hope it could help
    Hemendra:Yesterday is just a memory,Tomorrow we may never see
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

  • Share all folders and files between two OSX partitions

    So I have two partitions on my drive, one running 10.9, the other running 10.10 beta. I'm having a hard time figuring out how to make all folders read/write accessible from the other partition. I'd like to be able to access them easily, so that I don't have to change back over to 10.9 every time I want to watch a movie or access one of my files in one of my folders.
    All of the info I can find online is totally focused on how to share files between, say, a windows partition and osx partition for example, all the drivers needed etc... and I'm having a hard time just figuring out how to set permissions or whatever is needed to just get those pesky red dots off my folder icons and have them open and available form either partition.
    Thanks for any help.
    For what it's worth, I've tried hitting "get info" on one of the folders I know I can't get to from the other side (basically, all the main folders in my user except Public), and Everyone has Read Access (I can't even get in for Read at this point from other partition so I'm guessing that's not the right place). My user on the other partition is same username.
    Possibly a beta issue with Yosemite, or is there something I'm missing?

    This is a screen shot of the shared folder between my 2 partitions (10.6 and 10.9).

  • Unlocking All Folders and Sub Folders When Sharing

    Is there a way to share files and unlock them automatically. I Have many hundreads of excel and word docs in folders and sub folders.
    After a day scratching my head trying to work out why I could not save them on the shared computer I realized that I needed to unlock the folder.
    Excel does not have in its preferences anything that suggest this....it gets old real quick opening each file and then typing my computer password for each folder/ file etc....truly hope this can be done.
    Thanks in advance!

    Anyone???

  • CAN I PUT ALL MY FOLDERS AND INFO IN ONE MASTER FOLDER SO THAT IT'S EASY TO BACKUP PERIODICALLY?

    Hello,
    I thought of a solution to backing my files up in a quick way instead of having to look around all over my hard drive to drag my music, photos, documents, etc into my external hard drives for backup. (which is the current method I use)
    Id like to know if there would be any downsides simply putting all of the information like: music, documents, photos, videos and downloads (not including Applications) into one unique file.
    I am trying to avoid using Time Machine and backup Applications. I understand you can also program hard drives to mirror each other, but I belive my current external hard drives do not support this.
    The question is basically: could it be harmful in any to  store ALL(or as much) of your info that requires periodic backup into one master folder? Or does anyone know of any rule that may go against this solution?
    Thanks beforehand for the feedback.
    Emmi.

    Emmi Kirschen wrote:
    ... Id like to know if there would be any downsides simply putting all of the information like: music, documents, photos, videos and downloads (not including Applications) into one unique file.
    Yes.
    A long time ago Apple did not force users into keeping their files in specifed locations, such as music in the Music folder, movies in the Movies folder etc. However, iTunes, iMovie, iPhoto all have evolved to the point that Apple has made it difficult for us to do anything other than follow their recommended locations.
    There are certainly ways around this - you can specify alternate locations for your iTunes Library and your iPhoto Library for instance, but you will be swimming against the tide. This will undoubtedly cause problems that will be difficult to diagnose because you will be a lone outlier, attempting to circumvent Apple's preferred organizational method.
    I understand that you do not want to use Time Machine, but again this is Apple's recommended (if arguably heavy-handed) way of doing things. You can easily configure Time Machine to exclude folders that you do not want it to back up. If Time Machine does not address your needs, then consider Carbon Copy Cloner. It can also be customized to back up only those folders you specify: music, documents, photos, videos and downloads if that is your wish, and it can perform on a schedule.
    I believe you will find it more convenient - and assure you it will be much less likely to cause difficulty - than what you propose.

  • How could I remove all folders and files on ../queue/deferred/SMTP-Deliver/* ( This is deferred queue )?

     

    I'm assuming this is Netscape Messaging Server 4.x as your example looks like NMS's queue path and not iMS's.
    You can simpily stop the server, rm all the files under that directory and restart the server.
    When the server starts back up it will scan the queue area and update the control files with what it does (or does not) find the queue area.
    Hope this helps!
    -Chris

  • Read & Write all folders and files

    How do I allow another account user read & write privileges to all my files and folders? I have set the other user as an administrator however each file and folder that i've copied into their documents folder still need to be changed individually (through the Get Info window) in order to save changes or add new files to them. This is very time consuming, so is there an easier way?

    Not exactly what you are looking for but maybe some useful information:
    http://www.computerworld.com.au/article/197922/useraccounts_file_sharing_leopard_whatnew?pp=1&fp=2&fpid=2

  • Is there a way to have all folders and files line up all the time by default?

    I was wondering if there was a way to get all files and folders on the desktop and within locations like Downloads and Documents to automatically align to grid by default without user intervention.
    If so, how can I do this?
    Thanks!

    I was wondering if there was a way to get all files and folders on the desktop and within locations like Downloads and Documents
    Mario's post explains, how to arrange in colums in Finder windows.
    You can use the same method to arrange the items on the Desktop:
    Click on the empty Desktop to select it and to bring the Finder forward, press  the key combination ⌘J.
    Select "Snap to Grid" and set the spacing and icon size.
    Select an option how you want to sort them, e.g. by kind.
    Regards
    Léonie

  • How can i see folders and files with a 'Ñ' on his names?

    hi everybody, i'm a newer with MacOS, i've buy a MacBook Pro last Friday on Bogotá - Colombia, last nigth i plugged an external hard disk drive with many folders including a folder called: "Microsoft Office 2011 Español", when i explorer the hard disk i can't see this folder, i rename this folder on my pc on windows 7 and remove the word "Español" after that i was able to see the folder
    i think that it is a configuration of OS, so can anybody help me to fix this problem?

    Halo Mattias,
    i using this function get file file name and directory:
    at selection-screen on value-request for p_file.
      call function 'F4_FILENAME'
        exporting
          program_name  = syst-cprog
          dynpro_number = syst-dynnr
          field_name    = 'P_FILE'
        importing
          file_name     = p_file.
    Rgds,
    Wilibrodus

  • I need so sync all settings and files from one MBP to my new MBP HELP!!!

    Ok, so due to heat issue i am getting a brand new mbp as a replacement from apple this week, it should arrive in 2 or 3 days! Only thing is i have my origional one set up to perfection, it has all my settings nailed down and all applications etc that i use installed and ready to go. is there any way that when my replacement unit arrives that i can sync the 2? so that all my os x settings, e-mail accounts etc AND all my files, itunes libruary, iphoto libruary (over 5000 photos!) are safely transported to the new machine and ready to use?
    Thanks fellow mbp forum geek dudes! =D
    Macbook Pro 2.16 7200rpm Hd   Mac OS X (10.4.6)   Boy is It Hot

    The heat was pretty bad, like i said, botom of case getting to massive temperatures. Even when just surfing the net etc. The problem for me was that it was so hot that you couldnt touch it for more than about a second, and you certianly couldnt use it on your lap. I also found that the fans were not coming on to a high setting when the laptop was really hot, and this was not helping the issue. Apple were amazing though. I rang them and they ran me through some tests, these didnt work so i said i wanted a replacement, they didnt argue or try to put me off though. They fully respected my desicion and ordered me a new laptop the same day. I even get to keep the old one untill after the replacement arrives so that i can do the whole sync thing that caused me to start this topic!

  • Accessing Windows Drive its folders and files through KM

    Hi All,
    I have portal server installed in my laptop with KM, i would like to access windows C drive with all folders and files in my local machine what are the configurations i have to do.
    One more thing
    In real time scenario can we use CM repository, my requiremtn is to store documents of diffrent king which repository we can use which data base what configurations we have to set, basically what is the difference between internal and external repositories.
    regards,
    Murali

    Hi Murali,
    Internal repositories are those which come created in the KM like etc, documents and many more.
    External repositories are folders on diff locations (either on server or at other system) which are mapped to KM as repositories.
    Now. about ur requirement : You can try mapping the path c:\ as a folder in KM by making a File Repository manager.
    For storing different kind of  documents you can make different folders in Windows and map them as repositories by configuring File Rep managers for them
    See this[ link|http://help.sap.com/saphelp_nw04s/helpdata/en/e3/92322ab24e11d5993800508b6b8b11/frameset.htm]  to know about configuring a file repository manager.
    I hope it helps.
    Regards,
    Sumit

  • Taking Ownership of folders and files

    So I am doing what sure seems like way too much work to do something rather simple in GUI. There seem to be many topics on this and I base my code off of their results, but it isn't working entirely. Hopefully an easy one for you folks!  I am trying
    to take ownership of a path, be it a file or folder.  I DO NOT want to use a separate module like PSCX as not all machines will have the module.
    I created a function based off the code I found at the end of
    http://social.technet.microsoft.com/Forums/en-US/87679d43-04d5-4894-b35b-f37a6f5558cb/ that I can pass a path to singularly or I was hoping to be able to pipe Get-ChildItem to it.  When I do "Get-ChildItem -Path D:\Permissions\TopFolder -Recurse
    -Force | Take-Ownership" it seemed to work, but then I noticed it only seems to work going one layer deep. The text output for troubleshooting shows it recursing all the way through, but yet Owner is not being set all the way down.
    Folder layout:
    D:\Permissions\TopFolder
    D:\Permissions\TopFolder\FirstFolder
    D:\Permissions\TopFolder\FirstFile.txt
    D:\Permissions\TopFolder\FirstFolder\SecondFolder
    D:\Permissions\TopFolder\FirstFolder\SecondFile.txt
    D:\Permissions\TopFolder\FirstFolder\SecondFolder\ThirdFolder
    D:\Permissions\TopFolder\FirstFolder\SecondFolder\ThirdFile.txt
    Function Take-Ownership {
    [CmdletBinding(DefaultParameterSetName=”Set01”)]
    Param(
    [parameter(Mandatory=$true,ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True,Position=1,ParameterSetName='Set01')]
    [string]$Path,
    [parameter(Mandatory=$true,ValueFromPipelinebyPropertyName=$True,ParameterSetName='Set02')]
    [Alias('FullName')][string]$FullPath
    ) # End of Param()
    Begin {
    # Check that script was Run as Administrator
    If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
    [Security.Principal.WindowsBuiltInRole] "Administrator")) {
    Write-Host -ForegroundColor Red -BackgroundColor Black "`n ERROR: You MUST have Administrator rights to run this script!"
    Write-Host -ForegroundColor Red -BackgroundColor Black " Re-run this script as an Administrator!`n"
    Break
    #P/Invoke'd C# code to enable required privileges to take ownership and make changes when NTFS permissions are lacking
    $AdjustTokenPrivileges = @"
    using System;
    using System.Runtime.InteropServices;
    public class TokenManipulator
    [DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
    internal static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall,
    ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen);
    [DllImport("kernel32.dll", ExactSpelling = true)]
    internal static extern IntPtr GetCurrentProcess();
    [DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
    internal static extern bool OpenProcessToken(IntPtr h, int acc, ref IntPtr
    phtok);
    [DllImport("advapi32.dll", SetLastError = true)]
    internal static extern bool LookupPrivilegeValue(string host, string name,
    ref long pluid);
    [StructLayout(LayoutKind.Sequential, Pack = 1)]
    internal struct TokPriv1Luid
    public int Count;
    public long Luid;
    public int Attr;
    internal const int SE_PRIVILEGE_DISABLED = 0x00000000;
    internal const int SE_PRIVILEGE_ENABLED = 0x00000002;
    internal const int TOKEN_QUERY = 0x00000008;
    internal const int TOKEN_ADJUST_PRIVILEGES = 0x00000020;
    public static bool AddPrivilege(string privilege)
    try
    bool retVal;
    TokPriv1Luid tp;
    IntPtr hproc = GetCurrentProcess();
    IntPtr htok = IntPtr.Zero;
    retVal = OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok);
    tp.Count = 1;
    tp.Luid = 0;
    tp.Attr = SE_PRIVILEGE_ENABLED;
    retVal = LookupPrivilegeValue(null, privilege, ref tp.Luid);
    retVal = AdjustTokenPrivileges(htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero);
    return retVal;
    catch (Exception ex)
    throw ex;
    public static bool RemovePrivilege(string privilege)
    try
    bool retVal;
    TokPriv1Luid tp;
    IntPtr hproc = GetCurrentProcess();
    IntPtr htok = IntPtr.Zero;
    retVal = OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok);
    tp.Count = 1;
    tp.Luid = 0;
    tp.Attr = SE_PRIVILEGE_DISABLED;
    retVal = LookupPrivilegeValue(null, privilege, ref tp.Luid);
    retVal = AdjustTokenPrivileges(htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero);
    return retVal;
    catch (Exception ex)
    throw ex;
    Add-Type $AdjustTokenPrivileges
    # Activate necessary admin privileges to make changes without NTFS perms on the folder
    [void][TokenManipulator]::AddPrivilege("SeRestorePrivilege") # Necessary to set Owner Permissions
    [void][TokenManipulator]::AddPrivilege("SeBackupPrivilege") # Necessary to bypass Traverse Checking
    [void][TokenManipulator]::AddPrivilege("SeTakeOwnershipPrivilege") # Necessary to override File Permissions
    $Admin = New-Object System.Security.Principal.NTAccount("BUILTIN\Administrators")
    $NewDirACL = New-Object System.Security.AccessControl.DirectorySecurity
    $NewFileACL = New-Object System.Security.AccessControl.FileSecurity
    $NewDirACL.SetOwner($Admin)
    $NewFileACL.SetOwner($Admin)
    } # End of Begin {}
    Process {
    if( $FullPath.Length -gt 0 ) {
    if( Test-Path $FullPath ) {
    $Path = $FullPath
    if( Test-Path $Path -PathType Container ) {
    "Take Ownership: $Path"
    $Folder = Get-Item $Path -Force
    $Folder.SetAccessControl($NewDirACL)
    } elseif( Test-Path $Path -PathType Leaf ) {
    "Take Ownership: $Path"
    $File = Get-Item $Path -Force
    $File.SetAccessControl($NewFileACL)
    } else {
    Write-Host -ForegroundColor Red -BackgroundColor Black "ERROR: Path does not exist: $Path"
    } # End of Process {}
    End { } # End of End {}
    } # End of Function Take-Ownership
    To run this I have been doing:
    PS D:\> $Folder = 'D:\Permissions\TopFolder'
    PS D:\> Get-Item $Folder | Get-Acl
    Directory: D:\Permissions
    Path Owner
    TopFolder DOMAIN\user1
    PS D:\> Get-ChildItem $Folder -Force -Recurse | Get-Acl
    Directory: D:\Permissions\TopFolder
    Path Owner
    FirstFolder DOMAIN\user1
    FirstFile.txt DOMAIN\user1
    Directory: D:\Permissions\TopFolder\FirstFolder
    Path Owner
    SecondFolder DOMAIN\user1
    SecondFile.txt DOMAIN\user1
    Directory: D:\Permissions\TopFolder\FirstFolder\SecondFolder
    Path Owner
    ThirdFolder DOMAIN\user1
    ThirdFile.txt DOMAIN\user1
    PS D:\>
    PS D:\> Get-Item $Folder | Take-Ownership
    Take Ownership: D:\Permissions\TopFolder
    PS D:\> Get-ChildItem $Folder -Force -Recurse | Take-Ownership
    Take Ownership: D:\Permissions\TopFolder\FirstFolder
    Take Ownership: D:\Permissions\TopFolder\FirstFile.txt
    Take Ownership: D:\Permissions\TopFolder\FirstFolder\SecondFolder
    Take Ownership: D:\Permissions\TopFolder\FirstFolder\SecondFile.txt
    Take Ownership: D:\Permissions\TopFolder\FirstFolder\SecondFolder\ThirdFolder
    Take Ownership: D:\Permissions\TopFolder\FirstFolder\SecondFolder\ThirdFile.txt
    PS D:\>
    PS D:\>
    PS D:\> Get-Item $Folder | Get-Acl
    Directory: D:\Permissions
    Path Owner
    TopFolder BUILTIN\Administrators
    PS D:\> Get-ChildItem $Folder -Force -Recurse | Get-Acl
    Directory: D:\Permissions\TopFolder
    Path Owner
    FirstFolder BUILTIN\Administrators
    FirstFile.txt BUILTIN\Administrators
    Directory: D:\Permissions\TopFolder\FirstFolder
    Path Owner
    SecondFolder DOMAIN\user1
    SecondFile.txt DOMAIN\user1
    Directory: D:\Permissions\TopFolder\FirstFolder\SecondFolder
    Path Owner
    ThirdFolder DOMAIN\user1
    ThirdFile.txt DOMAIN\user1
    PS D:\>
    I don't know why this isn't working.  The output text shows I went through the subfolders and files...HELP!
    Find this post helpful? Does this post answer your question? Be sure to mark it appropriately to help others find answers to their searches.

    Here is the end result. I am looking to add a '-Recurse'/'-Force' switches to give another option to not have to Get-ChildItem and pipe it to the function and possibly a '-User' parameter to be able to specify who to set as owner, but both of those ideas
    are untested.
    Here is the code.  Hope it helps someone else.
    Function Take-Ownership {
    <#
    .SYNOPSIS
    This function takes ownership of a file or folder and sets it back to 'BUILTIN\Administrators'.
    .DESCRIPTION
    This function takes ownership of a file or folder and sets it back to 'BUILTIN\Administrators'.
    This will work even when the user does not have ownership or existing permissions on the file or folder.
    .EXAMPLE
    PS C:\> Take-Ownership -Path $Path
    Takes ownership of the individual folder or file. The -Path is optional as long as $Path
    is the first parameter.
    .EXAMPLE
    PS C:\> Get-Item $Path | Take-Ownership
    Takes ownership of the individual folder or file.
    .EXAMPLE
    PS C:\> Get-ChildItem $Path -Recurse -Force | Take-Ownership
    Recurse through all folders and files, including hidden, and takes ownership.
    #>
    [CmdletBinding()]
    Param(
    [parameter(Mandatory = $true, ValueFromPipeline = $True, ValueFromPipelinebyPropertyName = $True, Position = 0)]
    [Alias('FullName')]
    [string]$Path
    ) # End of Param()
    Begin {
    # Check that script was Run as Administrator
    If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
    [Security.Principal.WindowsBuiltInRole] "Administrator")) {
    Write-Host -ForegroundColor Red -BackgroundColor Black "`n ERROR: You MUST have Administrator rights to run this script!"
    Write-Host -ForegroundColor Red -BackgroundColor Black " Re-run this script as an Administrator!`n"
    Return
    #P/Invoke'd C# code to enable required privileges to take ownership and make changes when NTFS permissions are lacking
    $AdjustTokenPrivileges = @"
    using System;
    using System.Runtime.InteropServices;
    public class TokenManipulator
    [DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
    internal static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall,
    ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen);
    [DllImport("kernel32.dll", ExactSpelling = true)]
    internal static extern IntPtr GetCurrentProcess();
    [DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
    internal static extern bool OpenProcessToken(IntPtr h, int acc, ref IntPtr
    phtok);
    [DllImport("advapi32.dll", SetLastError = true)]
    internal static extern bool LookupPrivilegeValue(string host, string name,
    ref long pluid);
    [StructLayout(LayoutKind.Sequential, Pack = 1)]
    internal struct TokPriv1Luid
    public int Count;
    public long Luid;
    public int Attr;
    internal const int SE_PRIVILEGE_DISABLED = 0x00000000;
    internal const int SE_PRIVILEGE_ENABLED = 0x00000002;
    internal const int TOKEN_QUERY = 0x00000008;
    internal const int TOKEN_ADJUST_PRIVILEGES = 0x00000020;
    public static bool AddPrivilege(string privilege)
    try
    bool retVal;
    TokPriv1Luid tp;
    IntPtr hproc = GetCurrentProcess();
    IntPtr htok = IntPtr.Zero;
    retVal = OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok);
    tp.Count = 1;
    tp.Luid = 0;
    tp.Attr = SE_PRIVILEGE_ENABLED;
    retVal = LookupPrivilegeValue(null, privilege, ref tp.Luid);
    retVal = AdjustTokenPrivileges(htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero);
    return retVal;
    catch (Exception ex)
    throw ex;
    public static bool RemovePrivilege(string privilege)
    try
    bool retVal;
    TokPriv1Luid tp;
    IntPtr hproc = GetCurrentProcess();
    IntPtr htok = IntPtr.Zero;
    retVal = OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok);
    tp.Count = 1;
    tp.Luid = 0;
    tp.Attr = SE_PRIVILEGE_DISABLED;
    retVal = LookupPrivilegeValue(null, privilege, ref tp.Luid);
    retVal = AdjustTokenPrivileges(htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero);
    return retVal;
    catch (Exception ex)
    throw ex;
    Add-Type $AdjustTokenPrivileges
    # Activate necessary admin privileges to make changes without NTFS perms on the folder
    [void][TokenManipulator]::AddPrivilege("SeRestorePrivilege") # Necessary to set Owner Permissions
    [void][TokenManipulator]::AddPrivilege("SeBackupPrivilege") # Necessary to bypass Traverse Checking
    [void][TokenManipulator]::AddPrivilege("SeTakeOwnershipPrivilege") # Necessary to override File Permissions
    } # End of Begin {}
    Process {
    # Process for taking Ownership of the folder
    # - Specify the NT Account user to set as Owner (BUILTIN\Administrators)
    # - Create a new ACL object for the sole purpose of defining a new owner
    # - Establish the new ACL as owned by BUILTIN\Administrators, thus
    # guaranteeing the following ACL changes can be applied.
    # - Then apply that update to the existing folder's ACL which merges
    # the proposed changes (new owner) into the folder's actual ACL
    # - - IN OUR CASE OVERWRITING THE OWNER
    # - Additional Documentation:
    # http://msdn.microsoft.com/en-us/library/System.Security.AccessControl(v=vs.110).aspx
    $Admin = New-Object System.Security.Principal.NTAccount("BUILTIN\Administrators")
    $NewDirACL = New-Object System.Security.AccessControl.DirectorySecurity
    $NewFileACL = New-Object System.Security.AccessControl.FileSecurity
    $NewDirACL.SetOwner($Admin)
    $NewFileACL.SetOwner($Admin)
    if( Test-Path $Path -PathType Container ) {
    $Folder = Get-Item $Path -Force
    $Folder.SetAccessControl($NewDirACL)
    } elseif( Test-Path $Path -PathType Leaf ) {
    $File = Get-Item $Path -Force
    $File.SetAccessControl($NewFileACL)
    } else {
    Write-Host -ForegroundColor Red -BackgroundColor Black "ERROR: Path does not exist: $Path"
    } # End of Process {}
    End { } # End of End {}
    } # End of Function Take-Ownership
    Find this post helpful? Does this post answer your question? Be sure to mark it appropriately to help others find answers to their searches.

Maybe you are looking for