Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - changing file ownership, "powershell way", anyone?

Reply
 
Old 12-30-2006   #1 (permalink)
Gilles Pion


 
 

changing file ownership, "powershell way", anyone?

Hello everybody,

I've googled this group and elsewhere without finding answer to my question.

What is the "powershell way" to change file ownership?

Even in this newsgroups I've found only answers to this question using
"subinacl".

Could somebody give information to do this inside powershell?

Thanks in advance,

--
Gilles "Cool Raoul" - http://coolraoul.cvp-net.com/

My System SpecsSystem Spec
Old 12-30-2006   #2 (permalink)
/\\/\\o\\/\\/ [MVP]


 
 

Re: changing file ownership, "powershell way", anyone?

these blogentries might help

http://mow001.blogspot.com/2006/01/a...le-acl-in.html
http://mow001.blogspot.com/2005/10/m...r-working.html
http://mow001.blogspot.com/2005/10/u...-to-types.html

greetings /\/\o\/\/
http://ThePowerShellGuy.com

"Gilles Pion" <nosuchuser@nosuchdomain.com> wrote in message
newsokcp2tfboc333a341g5p3i1n176stfce7@4ax.com...
> Hello everybody,
>
> I've googled this group and elsewhere without finding answer to my
> question.
>
> What is the "powershell way" to change file ownership?
>
> Even in this newsgroups I've found only answers to this question using
> "subinacl".
>
> Could somebody give information to do this inside powershell?
>
> Thanks in advance,
>
> --
> Gilles "Cool Raoul" - http://coolraoul.cvp-net.com/


My System SpecsSystem Spec
Old 12-31-2006   #3 (permalink)
Gilles Pion


 
 

Re: changing file ownership, "powershell way", anyone?

Ref: <8B64BB69-D6C4-4304-A1DE-2E4030A8E12C@microsoft.com> de "/\\/\\o\\/\\/
[MVP]" <mow001@hotmail.NoSpam>
>these blogentries might help
>
>http://mow001.blogspot.com/2006/01/a...le-acl-in.html
>http://mow001.blogspot.com/2005/10/m...r-working.html
>http://mow001.blogspot.com/2005/10/u...-to-types.html



Thanks, I had already noticed those pages but I have been unable reproduce the
examples:

PS M:\var\tmp> (gi test.txt).get_owner()
Method invocation failed because [System.IO.FileInfo] doesn't contain a method
named 'get_owner'.
At line:1 char:24
+ (gi test.txt).get_owner( <<<< )

It seems that my powershell implementation doesn't know about "get_owner" (and
"set_owner" too) methods



Anyway, the following script seems to work partially (only when the owner is
myself or a group I belongs to)
==================================================================
function f_chown {
param(
[System.object]$the_file,
[system.security.principal.ntaccount]$the_owner
)
$acl = ($the_file | get-Acl )
$acl.setowner($the_owner)
$the_file | set-Acl -aclobject $acl
}


$accountname=$args[0]
$filename =$args[1]
$account= new-object system.security.principal.ntaccount($accountname)
$fileobj = (get-Item $filename)


f_chown $fileobj $accountname
==================================================================
--
Gilles "Cool Raoul" - http://coolraoul.cvp-net.com/
My System SpecsSystem Spec
Old 12-31-2006   #4 (permalink)
/\\/\\o\\/\\/ [MVP]


 
 

Re: changing file ownership, "powershell way", anyone?

the get_owner() Methods are custom methods I did make (in the post about
typedata), to make it more easy to reach

in the update typedate post I explain how I did add them


Greetings /\/\o\/\/

"Gilles Pion" <nosuchuser@nosuchdomain.com> wrote in message
news:lu3fp2t87vpie92uu6lutjgrhl9e1vq1dk@4ax.com...
> Ref: <8B64BB69-D6C4-4304-A1DE-2E4030A8E12C@microsoft.com> de
> "/\\/\\o\\/\\/
> [MVP]" <mow001@hotmail.NoSpam>
>>these blogentries might help
>>
>>http://mow001.blogspot.com/2006/01/a...le-acl-in.html
>>http://mow001.blogspot.com/2005/10/m...r-working.html
>>http://mow001.blogspot.com/2005/10/u...-to-types.html

>
>
> Thanks, I had already noticed those pages but I have been unable reproduce
> the
> examples:
>
> PS M:\var\tmp> (gi test.txt).get_owner()
> Method invocation failed because [System.IO.FileInfo] doesn't contain a
> method
> named 'get_owner'.
> At line:1 char:24
> + (gi test.txt).get_owner( <<<< )
>
> It seems that my powershell implementation doesn't know about "get_owner"
> (and
> "set_owner" too) methods
>
>
>
> Anyway, the following script seems to work partially (only when the owner
> is
> myself or a group I belongs to)
> ==================================================================
> function f_chown {
> param(
> [System.object]$the_file,
> [system.security.principal.ntaccount]$the_owner
> )
> $acl = ($the_file | get-Acl )
> $acl.setowner($the_owner)
> $the_file | set-Acl -aclobject $acl
> }
>
>
> $accountname=$args[0]
> $filename =$args[1]
> $account= new-object system.security.principal.ntaccount($accountname)
> $fileobj = (get-Item $filename)
>
>
> f_chown $fileobj $accountname
> ==================================================================
> --
> Gilles "Cool Raoul" - http://coolraoul.cvp-net.com/


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
"Extensible Authentication Protocol" service gives "The system cannot find the file specified" error Vista networking & sharing
Shortcut changes when changing attribute from "Normal window" to "Maximized" Vista General
PowerShell installation problem - Vista - "This machine disabled for file encryption." PowerShell
Deleted "music" folder, can't take ownership of replacement. Vista file management
Changing "mailto" protocol via registry--no "clients" file under HKEY_USERS Vista mail


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46