RSS

new-object

07 May

1 the common command

 
$r = Get-WmiObject -Class Win32_OperatingSystem 
$system = New-Object System.Management.Automation.PSObject

Add-Member -InputObject $system -MemberType Noteproperty -Name SystemDevice -Value $r.SystemDevice
Add-Member -InputObject $system -MemberType Noteproperty -Name SystemDrive -Value $r.SystemDrive
Add-Member -InputObject $system -MemberType Noteproperty -Name SystemDirectory -Value $r.SystemDirectory

$system

2 one line but not easy to understand

$r = Get-WmiObject -Class Win32_OperatingSystem 
$system = New-Object System.Management.Automation.PSObject
$system | Add-Member -MemberType Noteproperty -Name SystemDevice -Value $r.SystemDevice -PassThru |
Add-Member -MemberType Noteproperty -Name SystemDrive -Value $r.SystemDrive -PassThru |
Add-Member -MemberType Noteproperty -Name SystemDirectory -Value $r.SystemDirectory

$system

3 use one line but easy to understand

$r = Get-WmiObject -Class Win32_OperatingSystem 
$system = New-Object System.Management.Automation.PSObject -Property @{
SystemDevice = $r.SystemDevice
SystemDrive = $r.SystemDrive
SystemDirectory = $r.SystemDirectory
}
$system

Advertisements
 
Leave a comment

Posted by on May 7, 2010 in Powershell

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: