PowerShell versions difference (Version. 1.0 vs CTP Version. 2.0) one of many…

Its my personal opinion that this useful feature has been broken its functionality.  I’m talking about the change in *.Put().  In PowerShell Version 1.0, when doing the following commands will help you change the ‘Description’ value of your computer:

##################################################################################
## Changing the Server Description – Version 1.0 only
##################################################################################

$ServerDescChg = get-wmiobject -Class "Win32_OperatingSystem" -ComputerName "TEST"
$ServerDescChg.description      ## Description has no value

# Next line will set the value for "Description" to be "Test Server"

$ServerDescChg.Description = "Test Server"
$ServerDescChg.put

Script              : $this.PSBase.Put()
OverloadDefinitions : {System.Object Put();}
MemberType          : ScriptMethod
TypeNameOfValue     : System.Object
Value               : System.Object Put();
Name                : Put
IsInstance          : False

##————————————————————
## Description is change put server isn’t updated yet
##————————————————————
PS C:\developer\PSscripts> $ServerDescChg.description
EAP Test Server

##——————————————————–
## Adding the $true will update the server description
##——————————————————–
$ServerDescChg.put($true)

#############  PowerShell Version 1.0 only ##############################################

Now, in PowerShell CTP Version 2.0, we have lost this functionality and the *.PUT() script method has change to a be a System.Management object.  So, the *.PUT(), along with the *.Delete() methods are gone.

#####################################################################################
## Changing the Server Description – Using PowerShell CTP Version 2.0
#####################################################################################

$ServerDescChg = get-wmiobject -Class "Win32_OperatingSystem" -ComputerName "TEST"

$ServerDescChg.description      ## Description has no value

# Next line will set the value for "Description" to be "Test Server1"
$ServerDescChg.description = "TEST Server1"

## This line will not save the changes but will display the *.PUT() properties
$ServerDescChg.put

MemberType          : Method
OverloadDefinitions : {System.Management.ManagementPath Put(), System.Management.ManagementPath Put(PutOptions options)
                      , System.Void Put(ManagementOperationObserver watcher), System.Void Put(ManagementOperationObserv
                      er watcher, PutOptions options)}
TypeNameOfValue     : System.Management.Automation.PSMethod
Value               : System.Management.ManagementPath Put(), System.Management.ManagementPath Put(PutOptions options),
                       System.Void Put(ManagementOperationObserver watcher), System.Void Put(ManagementOperationObserve
                      r watcher, PutOptions options)
Name                : Put
IsInstance          : True

## The next line is supposed to save the value permanently into "Description" update the server
## but ends in an Error.
$ServerDescChg.put($True)
Cannot convert argument "0", with value: "True", for "Put" to type "System.Management.PutOptions": "Cannot convert valu
e "True" to type "System.Management.PutOptions". Error: "Invalid cast from ‘System.Boolean’ to ‘System.Management.PutOp
tions’.""
At line:1 char:19
+ $ServerDescChg.put <<<< ($True)

####################### End of PowerShell CTP Version 2.0 ######################################

Please, use the Get-Member CMDLET in order to list all properties and methods that you can use to work with your collection of objects. This will make your version 1.0 script not compatible with version 2.0.  And, you lost the ability to run a script that will remotely add/replace the "Description" value of any computer on the network.

Happy Coding!

Advertisements

About maxt2posh

I’m from Puerto Rico, have been working with computers since 1979. Throughout many years, I have worked with SQL Server Technologies, provided support to Windows Servers/Client machines, Microsoft Virtualization Technologies, and build some Visual Studio solutions. I’m a Microsoft PowerShell MVP since 2009 and MVP SAPIEN Technologies since 2010. I speak in most of the SQLSaturday, IT Pro and .NET camps events around the Florida’s State. Also founder of the Florida PowerShell User Group which meeting every 3rd Tuesday evening of the month.
This entry was posted in PowerShell. Bookmark the permalink.

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