Get-WmiObject -Class win32_computersystem $computername | Select-Object -Property model
If you don’t specify the -ComputerName parameter before placing your $computername variable, it thinks that you’re trying to perform this query:
“select DESKTOP01 from win32_computersystem”
Try adding the -Computername parameter, like so:
function Get-RegisterType {
[cmdletbinding()]
Param(
[Parameter(Mandatory=$True,Position=1)]
[string]$computername
)
Get-WmiObject -Class win32_computersystem -ComputerName $computername | Select-Object -Property model
}
As you can see in the help of Get-WMIObject the parameter -ComputerName is not allowed to be a positional paramter. And even for the readability it is recommended that you write all paramter names in scripts. Instead of Get-WMIObject I would recommend Get-CimInstance like this:
function Get-RegisterType {
[cmdletbinding()]
Param(
[Parameter(Mandatory=$True,Position=1)]
[string]$computername
)
Get-CimInstance -ClassName CIM_ComputerSystem -ComputerName $computername | Select-Object -Property model
}
I added the computer name parameter and removed the mandatory positional parameter from the param block.
When I run the function from the ISE I see it in the console but nothing happens.
function Get-RegisterType {
[cmdletbinding()]
Param(
[Parameter(Mandatory=$True)]
[string]$computername
)
Get-CimInstance -ClassName CIM_ComputerSystem -ComputerName $computername | Select-Object -Property model
}
PS C:\Users\aolynyk\Desktop> Get-RegisterType
Get-RegisterType : The term ‘Get-RegisterType’ is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
PS C:\Users\aolynyk\Desktop> Get-RegisterType
Get-RegisterType : The term ‘Get-RegisterType’ is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1