I noticed something strange. How is that I can do the following
Get-Service -Name ‘Alg’ (the parameter name accepts datatype string so this works)
But why does
Get-Service -InputObject ‘alg’ also work? (this parameter should not accept a string but a servicecontroller but still it works fine? What is happening under the hood here?
Thank you a lot js but are you saying that is happening? Where is this documented I wonder. According to website Microsoft it just wants servicecontroller?
-InputObject should just be accepting a string right? Get-Process gives an error when you try this with -inputobject as expected.
So can you or anyone else tell me what is happening?
… and … Powershell is made for administrators - not software developers. Powershell always “tries” to give an administrator what he/she/it probably expects. It does a lot of stuff implicitly under the hood to give a satisfying experience.
The docu says: Specifies ServiceController objects representing the services to be retrieved. Enter a variable that contains the objects, or type a command or expression that gets the objects. You can pipe a service object to this cmdlet.
So that means it does something it’s not supposed to do according to website but does it anyway? I’m grateful for your answer but if someone would tell me that it’s not supposed to do that but we don’t know why it does this and noone knows then I can accept that as an answer. Is there a command that I can see what it’s doing? Like a debug command? Maybe what js is describing that it does some coercion?
Powershell is very fluid with types. If it’s expecting one type, and it can convert what you give it to what it expects, it will do that. You can’t cast a string to a process in the same way.
[System.Diagnostics.Process]'cmd'
InvalidArgument: Cannot convert the "cmd" value of type "System.String" to type "System.Diagnostics.Process".
aaaah so basically if it can convert to a type it needs it will do that. This makes sense! Is there a command that shows the conversion it is doing like a debug command?
But thanks JS that is already a big part of the puzzle. Would be just great if we could see it in action as to say.