Reputation: 109
I try to write script (PowerShell) that return CPU name using Win32:
$temp = Get-WmiObject Win32_Processor
$temp.Name
function Get-CPU-Name {
[parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][System.Management.ManagementBaseObject]$Temp1
return $Temp1.Name
}
Get-CPU-Name
A function call should return the name of the processor, but it does not return anything. How to correctly pass a variable with the results of the "Get-WmiObject Win32_Processor" command to the function
Upvotes: 2
Views: 150
Reputation: 61198
You're almost there, but forgot to put the parameter inside param(..)
.
This should work:
function Get-CPU-Name {
param (
[parameter(Mandatory=$true, Position = 0)]
[System.Management.ManagementBaseObject]$Temp1
)
$Temp1.Name
}
Get-CPU-Name (Get-WmiObject Win32_Processor)
Upvotes: 2