Jump to content

Enumerate a Folder to get all subfolders and files on a Share?


Recommended Posts

I'm trying to figure out how I can grab all of the folder object names in a specified folder, this is what I have so far.

$DNSDomain      = @LogonDNSDomain
$GPOFolder      = "\SYSVOL\" & $DNSDomain & "\Policies"
$strComputer    = "."
$objFSO_GPO     = ObjCreate("Scripting.FileSystemObject")


If $DNSDomain = "" Then MsgBox(0, "Critical Error", "Target domain could not be obtained.")

If Not IsObj($objFSO_GPO) Then MsgBox(0, "Critical Error", "File System Object could not be created.")

MsgBox(0, "", $DNSDomain & $GPOFolder)

$objFSO_GPO_Folder  = $objFSO_GPO.GetFolder("\\" & $DNSDomain & $GPOFolder)
$arrGPO_SubFolders  = $objFSO_GPO.Subfolders

For $folder in $arrGPO_SubFolders
    MsgBox(0, "", $folder)
Next

I'm getting an error that "the requested action with this object failed." Can anyone tell me if I'm even headed in the right direction? PLS HELP! TIA.

My Additions:- RunAs AdminDeviant Fun:- Variable Sound Volume

Link to comment
Share on other sites

I'm trying to figure out how I can grab all of the folder object names in a specified folder, this is what I have so far.

$DNSDomain      = @LogonDNSDomain
$GPOFolder      = "\SYSVOL\" & $DNSDomain & "\Policies"
$strComputer    = "."
$objFSO_GPO     = ObjCreate("Scripting.FileSystemObject")

If $DNSDomain = "" Then MsgBox(0, "Critical Error", "Target domain could not be obtained.")

If Not IsObj($objFSO_GPO) Then MsgBox(0, "Critical Error", "File System Object could not be created.")

MsgBox(0, "", $DNSDomain & $GPOFolder)

$objFSO_GPO_Folder  = $objFSO_GPO.GetFolder("\\" & $DNSDomain & $GPOFolder)
$arrGPO_SubFolders  = $objFSO_GPO.Subfolders

For $folder in $arrGPO_SubFolders
    MsgBox(0, "", $folder)
Next

I'm getting an error that "the requested action with this object failed." Can anyone tell me if I'm even headed in the right direction? PLS HELP! TIA.

Are you getting that error for .GetFolder or .Subfolders? Post the text of the error.

Are you sure the domain name is the same as the server name? Can you connect manually to this ("\\" & $DNSDomain & $GPOFolder)?

:P

P.S. Just noticed you are taking .Subfolders of the wrong object. Use $objFSO_GPO_Folder.Subfolders instead. Also, in your For/Next loop nothing will be displayed because $folder is an object, so change that to MsgBox(0, "", $folder.Name) or some such...

:P

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...