Solved

Take ownership of multiple files

Posted on 2006-11-09
1
616 Views
Last Modified: 2012-06-21
I have the following script that will take ownership of 1 folder, what I want to do is to have this take ownership of a large amount of folders at once by either pulling the folder name from a text file or just listing it in the script.  So I have a directory called owner and say I have 10 folders under that called 1 through 10.. is this possible?

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery _
    ("Select * From Win32_Directory Where Name = 'C:\\Owner'")

For Each objFolder in colFolders
    objFolder.TakeOwnershipEx
Next
0
Comment
Question by:rtmcmullen
1 Comment
 
LVL 38

Accepted Solution

by:
Shift-3 earned 500 total points
ID: 17908310
From the original article (http://www.microsoft.com/technet/scriptcenter/resources/qanda/jan06/hey0111.mspx):
"The TakeOwnershipEx method enables us to take ownership not only of the folder C:\Scripts but also any subfolders found in C:\Scripts. If you don’t want to take ownership of the subfolders then use the TakeOwnership method instead."

So it should already work for the scenario you suggest.

If you did want to take ownership of several individual folders then you could use the script below, adding any desired folders to arrFolderList.

strComputer = "."

arrFolderList=Array("'C:\\Owner\\1'","'C:\\Owner\\2'")

For Each strFolder in arrFolderList
   Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
   Set colFolders = objWMIService.ExecQuery _
      ("Select * From Win32_Directory Where Name = " & strFolder)

   For Each objFolder in colFolders
      objFolder.TakeOwnershipEx
   Next
Next
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
split53 challenge 7 79
create an incrementing variable name AutoHotKey 5 80
Basic Java Case or If-Else statement... 3 43
Beginner to Unreal Engine 4 5 61
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now