Object copy

Hi Team,
How can I copy all the properties of an object ( in the below example $S=TypeName: System.ServiceProcess.ServiceController) to a PSCustom object by keeping some more additional properties of its properties. The below is the example…

$S=Get-Service DNS*
$obj = new-object -TypeName PSObject -property @{MyName=‘Admin’}

Now I need another Variable | object which contains all the $S|fl * along with $Obj|fl * ; my final target is to write-output with a single datatype.

$S=Get-Service DNS*
$S | Add-Member MyName 'Admin'

Sean’s point is correct - you don’t need to copy the object. PowerShell lets you add properties (and other members) directly to any object. So you should just add them to the ServiceController. PowerShell’s extensible type system (ETS) already adds numerous members to the base .NET object.

If for some reason you really do want to create a new object with all the same properties, piping the original object to Select-Object -Property * will do the trick. You’ll wind up with a PSObject containing a bunch of NoteProperties, instead of whatever type the original object was.

Wow. That is awesome. This is what I am looking for. Thanks Wyatt.