Search user in OU and compare to folder, if match execute script if doesn't match not execute script RRS feed

  • Question

  • This script deletes the files from the F:\ redirectfolder folder
    I need a script like this below but more complete:
    Get-ChildItem -Path F: \ redirectfolder -Include *. * -File -Recurse | foreach {$ _. Delete ()}

    This script deletes all files that are in this folder, OK.
    More precise is a script that deletes what is in the folder, but only of the users that are contained in OU Roaming.

    In the folder F: \ redirectfolder has the folder of each user contained in the roaming OU.

    I need a script that compares the users that are in the Roaming OU and in the folder F: \ redirectfolder,  if it is the same so, delete the files of each folder of the user, if it is not match do not delete

    Sunday, June 24, 2018 9:55 PM

All replies

  • File do not have "users"?  Files have "owners".

    Since we do 't write custom scripts I can only say that you need to learn how to retrieve the file owner  Which is part of the FileInfo structure.  Then test if that owner


    $f = Get-Item test.txt
    $ownerID = $f.GetAccessControl().Owner

    Then check that account against your OU by getting the distinguished name and matchi g it to the OU.

    Look in the Gallery for more example scripts.


    Sunday, June 24, 2018 10:22 PM