Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Take ownership of multiple files

Posted on 2006-11-09
1
Medium Priority
?
650 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 38

Accepted Solution

by:
Shift-3 earned 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
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…
Six Sigma Control Plans

618 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