# Takeown Powershell Module

By
,
Powershell
,
Modules
Published 2022-08-11

Link To Download
https://www.powershellgallery.com/packages/Takeown/1.0.1

These guys know all about takeown honest
These guys know all about takeown honest

# Yep Another Crescendo Module 🥱

No please give me a moment to explain, this is a world first. Trust. Search the powershell gallery if you do not beleive me. So why else would I commit my time to the masses? I bring a time of happiness back to the 90's with this little gem 💎

I love old skool DOS commands but not the parameters
I love old skool DOS commands but not the parameters

I really did love the 90's and the music it brung to the dance-floors up and down the 🇬🇧 UK and all the music being illegally played in farmers fields, where new types of music was being created, and the Rave scene began. Sadly I was a bit too young to be going to the illegal raves, as I was stuck at a military boarding school in the middle of no-where. Trust not much fun there. So why am I banging on about the 90's no it's not to re-live the days of Rave music but to remember a tool you may have forgotten about. So what is this tool you are talking about? 💥 It is in the title but it is the mighty takeown.exe So what is so great about this tool then? Well I recently used it to make a script to be the equivalent of a delprof script. For some weird reason even as a local or domain admin it didn't have access to some directories. I did use this in conjunction with another tool, but that shall come in another blog soon. Anyways back to the whole 90's vibe, and it is because I read somewhere that this was in NT4 which I believe was released in 1996. Sadly I don't have an NT4 Operating system to hand to find out, and I do not have a comments section so maybe send me a postcard if you have an NT4 system and want to confirm that fun but maybe not true statement.

# Set-ACL 🧨

Look I know the clever people in the Powershell team at the world of Microsoft brought us Set-ACL but again to me it needs a lot of attention to use the cmdlet correctly. I am not a crash-bang scripting just chucking things together and hoping for the best. I like to feel 100% confident in all the scripts I write that the cmdlet does or will do exactly what I programmed it to do with no side effects. So I know an official Powershell cmdlet exists for this job, but me personally being a simple man from a small town in the 🇬🇧 I like to keep things simple. I might have a super supportive amazing wife, but I also got blessed with 4 daughters who can make my life complicated enough, as well as 2 dogs 3 cats. So yeah if I have to spend more time studying a cmdlet rather than using the cmdlet then maybe that is not the cmdlet for me to use? Maybe that quote will go down in Powershell history, probably not, but sitting here typing this blog, it makes total sense to me, to reach back to the old-skool and use something I know that works is simple to use (apart from the parameter names) and gets the job done. Yes I know this may not be the fasted approach to getting the job done, but again do we not have background job capability to run long running scripts in Powershell...Yes we do. So again in my book that is that hurdle jumped.

# Set-Ownership 🎉

Do not stop reading...Bomb Queen wants you to pay more attention to what I am saying
Do not stop reading...Bomb Queen wants you to pay more attention to what I am saying

So another quick ramble but thinking 🤔 about it I was the only kid in my year who was allowed to drop 🇫🇷 French for GCSE. Why? I was really, really bad at it, about the only 🇫🇷 French I was good at saying was je suis désolé so fast-foward a number of years, and when I starting looking at DOS it just reminded me of French lessons at school. Nothing really made sense, it seemed like a totally foreign language I was going to have to learn, then as well as the command line you were issuing there were all these weird parameter names that just made it even more confusing. Then a really good friend of mine (well I wish he was, he has tweeted me a reply once or twice that means we are bff right?) aka Jeffrey Snover only went and invented Powershell. Something that was an object-orientated language but in English. Or well just words that made sense, parameters that made sense. 💥 So my journey with this most amazing language began, because I could understand it. Well to a certain degree at the start, but the more I used it the more it made sense. Enough rambling, I was thinking to keep this in-line with good quality spoken English...Ladies and Gentlemen I bring you Set-Ownership which is a complete wrapper with all the parameters of takeown

takeown Micorosft Documentation
https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/takeown

To put it right before your eyes 👀 a simple explanation on the right-hand-side telling you the new parameter name for the old parameter name like I am sure /S is for the system name of the computer, but -ComputerName for me is a lot more easier, and it goes with the common parameter list for this which other Powershell cmdlets use which again just makes this less like a foreign language to me and a lot more easier to understand.

# Parameters Explained 👨‍🏫

NAME
    Set-Ownership

SYNOPSIS
    PS wrapper module for takeown.exe


SYNTAX
    Set-Ownership [[-ComputerName] <String>] [[-RunAs] <String>] [[-Password] <String>] [[-Path] <String>]
    [-GiveAdminGroupOwnership] [-Recurse] [[-SupressConfirmation] <String>] [<CommonParameters>]


DESCRIPTION
    See https://adam-bacon.netlify.app/recent-modules/takeown/
    This tool allows an administrator to recover access to a file that was denied by re-assigning file ownership.
    Original Parameter List with new parameter name given:
     /S           system          Specifies the remote system to
                                  connect to. Now -ComputerName

     /U           [domain\]user   Specifies the user context under
                                  which the command should execute. Now -RunAs

     /P           [password]      Specifies the password for the
                                  given user context.
                                  Prompts for input if omitted. Now -Password

     /F           filename        Specifies the filename or directory
                                  name pattern. Wildcard "*" can be used
                                  to specify the pattern. Allows sharename\filename. Now -Path

     /A                           Gives ownership to the administrators
                                  group instead of the current user. Now -GiveAdminGroupOwnership

     /R                           Recurse: instructs tool to operate on
                                  files in specified directory and all
                                  subdirectories. Now -Recurse


PARAMETERS
    -ComputerName <String>

        Required?                    false
        Position?                    1
        Default value
        Accept pipeline input?       false
        Accept wildcard characters?  false

    -RunAs <String>

        Required?                    false
        Position?                    2
        Default value
        Accept pipeline input?       false
        Accept wildcard characters?  false

    -Password <String>

        Required?                    false
        Position?                    3
        Default value
        Accept pipeline input?       false
        Accept wildcard characters?  false

    -Path <String>

        Required?                    false
        Position?                    4
        Default value
        Accept pipeline input?       false
        Accept wildcard characters?  false

    -GiveAdminGroupOwnership [<SwitchParameter>]

        Required?                    false
        Position?                    named
        Default value                False
        Accept pipeline input?       false
        Accept wildcard characters?  false

    -Recurse [<SwitchParameter>]

        Required?                    false
        Position?                    named
        Default value                False
        Accept pipeline input?       false
        Accept wildcard characters?  false

    -SupressConfirmation <String>

        Required?                    false
        Position?                    5
        Default value
        Accept pipeline input?       false
        Accept wildcard characters?  false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer, PipelineVariable, and OutVariable. For more information, see
        about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216).

INPUTS

OUTPUTS

NOTES


        PARAMETER ComputerName
        Specifies the computer to run this cmdlet against, this will default to the local machine if not used
        PARAMETER RunAs
        Allows you to specify a user account in Domain\User format to run the cmdlet as which in turn will use this
        account specified to take the ownership
        PARAMETER Password
        Only need to use this parameter if you have specified the -RunAs which will detail the username, then you use
        this parameter to specify the password
        PARAMETER Path
        This is used to specify the file path to the direcotory or file you wish to take ownership of
        PARAMETER GiveAdminGroupOwnership
        Will give ownership of the file or directory specified to the administrator group on the computer it is being
        run on
        PARAMETER Recurse
        This allows you to apply the given command recursively through all direcotries and sub-directories
        PARAMETER SupressConfirmation
        Please see the official documentation but this supports either a Y or a N for this parameter. The Y option
        will supress the confirmation and the N option will skip it

# Example 🔈

Just a nice plain demo:-

Set-Ownership -Path C:\Users\Adz\Desktop\AdamBacon2022.pdf

Gave me the ownership on my CV I have on my desktop. Wahoo! But yeah in all seriousness this saved my bacon 🥓 (pun intended 😂) when I needed ownership of certain directories, and instead of doing it the point and click way recursively through lots, and lots of directories I used takeown.exe within my Powershell script. So as I got so much passion for Powershell I thought why not make this into a fully fledge cmdlet to remind people sometimes the old-skool tools just get the job done in a more simple manner. I do not have a masters degree in computer science, I don't claim to be super-intelligent, I just like to smash the jobs I get assigned to me in the most effiecient manner possible with me understanding the complete process A to Z.

# Pun 🤣

Think if I broke Powershell naming conventions and called this Do-Takeown you could of had
Think if I broke Powershell naming conventions and called this Do-Takeown you could of had
That is why we do not break Powershell naming conventions Verb-Noun

# Why do this now? 👴

Well I mention this on the home page but I am 40 now...I remember when I was young like single digit young 40 was proper well old age. So now being at this youthful stage of my life, I am thinking do all the new-school kids on the block know about these classic commands from a time before they were even born? Possibly, but most likely if it is not a Powershell cmdlet then to some people it is not worth using, or possiblly knowing about. Obviously scripts and modules I might develop in work-time have to stay at work, hence I normally do weird-and-amazing modules that may or may not be to everyones liking. So thought why not write a blog on a DOS tool I have recently used, but even better spend time on that to make it into a full on Powershell cmdlet through the power of Crescendo and bring this old-skool command back to life

I really hope you enjoyed this read, and please do not go turning super evil like Irredeemable did and become the worlds worst Super-Villain
I really hope you enjoyed this read, and please do not go turning super evil like Irredeemable did and become the worlds worst Super-Villain