Looking at your script, the error occurs specifically on this line:
$object = New-Object –TypeNamePSObject
The key issue here is actually a simple syntax error that's easy to miss. The hyphen before TypeNamePSObject
is actually an en-dash (–) instead of a regular hyphen (-). PowerShell only recognizes regular hyphens for parameter names.
Here's the corrected version:
$object = New-Object -TypeName PSObject
Notice two important corrections:
- Used a regular hyphen (-) instead of en-dash (–)
- Added a space between -TypeName and PSObject
While we're fixing your script, let me suggest a more modern approach using [PSCustomObject]
which is cleaner and avoids the Add-Member
calls:
$sServer = "Fully.Qualified.Computer.Name"
$os = Get-WmiObject -class Win32_OperatingSystem -computername $sServer
$bios = Get-WmiObject -class Win32_BIOS -computername $sServer
$object = [PSCustomObject]@{
OSBuild = $os.BuildNumber
OSVersion = $os.Version
BIOSSerial = $bios.SerialNumber
}
$object
The "parameter cannot be found" error typically appears when:
- You've misspelled a parameter name
- You're using the wrong type of dash/hyphen
- The parameter doesn't exist for that cmdlet in your PowerShell version
- You're missing required spaces between parameters and values
If you're ever unsure about a cmdlet's parameters, use Get-Help
:
Get-Help New-Object -Full
Or to see just the parameters:
(Get-Command New-Object).Parameters
Here's your entire script fixed and improved:
# Get system information from remote computer
$computer = "Fully.Qualified.Computer.Name"
try {
$os = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $computer -ErrorAction Stop
$bios = Get-WmiObject -Class Win32_BIOS -ComputerName $computer -ErrorAction Stop
[PSCustomObject]@{
ComputerName = $computer
OSBuild = $os.BuildNumber
OSVersion = $os.Version
BIOSSerial = $bios.SerialNumber
LastBoot = $os.ConvertToDateTime($os.LastBootUpTime)
}
}
catch {
Write-Warning "Failed to retrieve information from $computer"
Write-Warning $_.Exception.Message
}
The error message you're encountering is a classic PowerShell parameter binding issue. The script fails at the New-Object
cmdlet because of incorrect parameter syntax. Let's examine the problematic line:
$object = New-Object –TypeNamePSObject # Wrong
PowerShell is particular about parameter formatting. The correct version should use a space after the parameter name and proper dash characters:
$object = New-Object -TypeName PSObject # Correct
What makes this error particularly tricky is that the dashes you're using might be EN DASH (–) instead of regular hyphens (-). PowerShell only recognizes ASCII hyphens for parameters. Try retyping the command manually rather than copying.
Here's the fully corrected version with some additional improvements:
$sServer = "Fully.Qualified.Computer.Name"
# Using CIM cmdlets instead of WMI (modern approach)
$os = Get-CimInstance -ClassName Win32_OperatingSystem -ComputerName $sServer
$bios = Get-CimInstance -ClassName Win32_BIOS -ComputerName $sServer
$object = New-Object -TypeName PSObject -Property @{
OSBuild = $os.BuildNumber
OSVersion = $os.Version
BIOSSerial = $bios.SerialNumber
}
$object # Implicit Write-Output
The "parameter not found" error ranks among the most common PowerShell issues because:
- Parameter names are case-insensitive but spacing-sensitive
- Smart quotes/dashes from word processors can cause failures
- Some IDEs may auto-format parameters incorrectly
For PowerShell 4.0 and later, consider these cleaner approaches:
# Using [PSCustomObject] (PS 3.0+)
$object = [PSCustomObject]@{
OSBuild = $os.BuildNumber
OSVersion = $os.Version
BIOSSerial = $bios.SerialNumber
}
# Using Select-Object (PS 2.0+)
$object = $os | Select-Object @{
Name = 'OSBuild'
Expression = { $_.BuildNumber }
}, @{
Name = 'OSVersion'
Expression = { $_.Version }
}
When facing parameter binding issues:
- Use
Get-Command -Syntax New-Object
to see valid parameters - Check for hidden characters with
$line.ToCharArray() | ForEach-Object { [int]$_ }
- Try typing the command manually in console first
For WMI queries in modern PowerShell, consider migrating to CIM cmdlets (Get-CimInstance
) as they're more efficient and work consistently across PowerShell versions.