locked
Is there an Exclude switch for TAKEOWN? RRS feed

  • Question

  • I have a large number of old XP profile folders and all the new .V2 profile folders in the same directory on a server share.

    Unfortunately when these profiles were created, they used default Windows NTFS settings which did not include the Administrators group.

    So now I want to take ownership of all the XP profile folders so I can delete them while leaving the *.V2 profile folders alone.

    TAKEOWN works great but I am unable to figure out how to exclude *.V2 folder names.

    Does TAKEOWN not have an -Exclude switch or a way to accomplish what I'm trying to do? Thanks in advance.

    Friday, June 27, 2014 11:17 AM

Answers

  • Hi hsl,

    you can do this by pre-filtering the input to takeown:

    dir $rootfolder | Where { $_.Name -notlike "*.V2" } | %{ TAKEOWN /F $_.FullName }

    This (or something similar) should do it.

    Cheers,
    Fred


    There's no place like 127.0.0.1

    • Marked as answer by Highspeedlane Wednesday, July 2, 2014 9:41 PM
    Friday, June 27, 2014 11:47 AM

All replies

  • Hi hsl,

    you can do this by pre-filtering the input to takeown:

    dir $rootfolder | Where { $_.Name -notlike "*.V2" } | %{ TAKEOWN /F $_.FullName }

    This (or something similar) should do it.

    Cheers,
    Fred


    There's no place like 127.0.0.1

    • Marked as answer by Highspeedlane Wednesday, July 2, 2014 9:41 PM
    Friday, June 27, 2014 11:47 AM
  • Thanks Fred. I won't be able to test until Monday but as soon as I do will let you know. Thanks.
    Friday, June 27, 2014 11:49 AM
  • Fred that worked great.

    I'm a noob at PS scripting so hope you don't mind if I ask some questions in the future.

    Thanks again for your help.

    Wednesday, July 2, 2014 9:41 PM