Using [__ComObject] in PoSH v2

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 7 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
dennis.lindqvist
Posts: 41
Last visit: Tue Sep 10, 2019 6:57 am

Using [__ComObject] in PoSH v2

Post by dennis.lindqvist »

For some reason, the param defined in this code section isn't configured and can't be used.
I can't figure out why it doesn't work in PoSH v2 (tried both x86 and x64). :(
  1. function Test
  2. {
  3.  
  4.     param(
  5.     [Parameter(Mandatory=$true,
  6.         ValueFromPipeline=$true)]
  7.     [Alias('Definition')]
  8.     [__ComObject]
  9.     $Task
  10.     )
  11.    
  12. }
Last edited by dennis.lindqvist on Tue Dec 13, 2016 6:04 am, edited 2 times in total.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Params not defined in function

Post by jvierra »

What does "isn't configured" and "can't be used" mean or refer to? Did you write this? What did you intend it to do?
User avatar
dennis.lindqvist
Posts: 41
Last visit: Tue Sep 10, 2019 6:57 am

Re: Using [__ComObject] in PoSH v2

Post by dennis.lindqvist »

I simplified the code example.
It's actually from MS Window 7 resourse kit as part of the scheduled task powershell module.

The param -task is never "added" to the function.

(get-command test).parameters is empty

I've narrowed it down to the type [__ComObject] breaks the param definition.
Last edited by dennis.lindqvist on Tue Dec 13, 2016 6:05 am, edited 1 time in total.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Params not defined in function

Post by jvierra »

Type:
Test -?

It is added and is available.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Params not defined in function

Post by jvierra »

V2 does not support all of the command decorations.
[__COmObject] is not supported until V3.
User avatar
dennis.lindqvist
Posts: 41
Last visit: Tue Sep 10, 2019 6:57 am

Re: Using [__ComObject] in PoSH v2

Post by dennis.lindqvist »

jvierra wrote:V2 does not support all of the command decorations.
[__COmObject] is not supported until V3.
Did I mentioned it is from the Windows 7 RK that was released before PosH v3 was available?
Last edited by dennis.lindqvist on Tue Dec 13, 2016 6:06 am, edited 1 time in total.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Params not defined in function

Post by jvierra »

What resource kit?

PS 2 does not support that object. Try it at a prompt. It will throw an error in V2 but not in any later version.
User avatar
dennis.lindqvist
Posts: 41
Last visit: Tue Sep 10, 2019 6:57 am

Re: Using [__ComObject] in PoSH v2

Post by dennis.lindqvist »

jvierra wrote:What resource kit?
This resource kit:
Introducing the Windows 7 Resource Kit PowerShell Pack
https://blogs.msdn.microsoft.com/powers ... hell-pack/
jvierra wrote:PS 2 does not support that object. Try it at a prompt. It will throw an error in V2 but not in any later version.
I know, and that's the issue.

PoSH v2 do support it as my snippet is from the MS release of Windows 7 RK.

But never mind.
I figured out myself of how to use [__ComObject] in PoSH v2.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Using [__ComObject] in PoSH v2

Post by jvierra »

That is the PowerShell Pack and not the original release of the W7 RK. It was released much later. If your read the article carefully it makes this distinction clearly.

" the PowerShell Pack is available for download on code gallery."


The PS Pack was moved to the archive and is now no longer available.

If you figured out how to make [__ComObject] work in PS2 can you share it?
User avatar
dennis.lindqvist
Posts: 41
Last visit: Tue Sep 10, 2019 6:57 am

Re: Using [__ComObject] in PoSH v2

Post by dennis.lindqvist »

Just create a COM object and the data type will be available for typed variables.
Type ComObject.png
Type ComObject.png (41.29 KiB) Viewed 4569 times
It's pretty ugly to define a variable just to load the ComObject type.

Is there another way to have PoSH instanciate objects without creating a variable?
This topic is 7 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked