{"id":577,"date":"2008-08-07T00:04:25","date_gmt":"2008-08-07T08:04:25","guid":{"rendered":"http:\/\/www.sapien.com\/blog\/2008\/08\/07\/powershell-and-com-objects\/"},"modified":"2008-08-13T13:59:19","modified_gmt":"2008-08-13T21:59:19","slug":"powershell-and-com-objects","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2008\/08\/07\/powershell-and-com-objects\/","title":{"rendered":"PowerShell and COM objects."},"content":{"rendered":"<p align=\"left\">While developing a COM object for scripting use I wanted to provide a VBScript sample as well as a PowerShell sample.<\/p>\n<p align=\"left\">While creating the PowerShell sample I received an unexpected error message when setting a property value. Some quick review shows that PowerShell 1.0 (I did not check with the 2.0 CTP yet) cannot handle write-only COM properties.<\/p>\n<p align=\"left\">Consider the following PowerShell script:<\/p>\n<p align=\"left\">$obj = New-Object -comObject &#8220;PropertyTest.PropTest&#8221;<br \/>\n$obj.ReadWrite = &#8220;Some text&#8221;<br \/>\n$readonly = $obj.ReadOnly<br \/>\n$obj.WriteOnly = &#8220;some more text&#8221;<\/p>\n<p align=\"left\">The object&#8217;s properties behave as they are named. If you run these instructions one by one in PowerShell you get the\u00a0 following error message:<\/p>\n<p>Exception setting &#8220;WriteOnly&#8221;: &#8220;Type mismatch. (Exception from HRESULT: 0x80020<br \/>\n005 (DISP_E_TYPEMISMATCH))&#8221;<br \/>\nAt line:1 char:6<br \/>\n+ $obj.W &lt;&lt;&lt;&lt; riteOnly = &#8220;some more text&#8221;<\/p>\n<p>Read-write and read-only properties work fine, only write-only properties are affected. I have uploaded the test component here: <a href=\"ftp:\/\/ftp.sapien.com\/propertytest.dll\">PropertyTest.dll<\/a><\/p>\n<p>Obviously you need to run regsvr32 PropertyTest.dll if you want to test this.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>While developing a COM object for scripting use I wanted to provide a VBScript sample as well as a PowerShell sample. While creating the PowerShell sample I received an unexpected error message when setting a property value. Some quick review shows that PowerShell 1.0 (I did not check with the 2.0 CTP yet) cannot handle [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[25],"tags":[61,28,57],"class_list":["post-577","post","type-post","status-publish","format-standard","hentry","category-windows-powershell","tag-com","tag-powershell","tag-scripting"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/577","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=577"}],"version-history":[{"count":2,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/577\/revisions"}],"predecessor-version":[{"id":607,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/577\/revisions\/607"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=577"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=577"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=577"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}