11

I am new to the Powershell world. Below is my first script

$sServer = "Fully.Qualified.Computer.Name"

$os = Get-WmiObject -class Win32_OperatingSystem -computername $sServer
$object = New-Object –TypeNamePSObject
$object | Add-Member –MemberTypeNoteProperty –Name OSBuild –Value $os.BuildNumber
$object | Add-Member –MemberTypeNoteProperty –Name OSVersion –Value $os.Version
$object | Add-Member –MemberTypeNoteProperty –Name BIOSSerial –Value $bios.SerialNumber
Write-Output $object

When I run this script in PowershellISE, I get the following error.

New-Object : A parameter cannot be found that matches parameter name 'TypeNamePSObject'.
At C:\Users\someone\Desktop\SchwansScript.ps1:27 char:22
+ $object = New-Object –TypeNamePSObject
+                      ~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidArgument: (:) [New-Object],ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.NewObjectCommand

Unfortunately for me, it seems like "A parameter cannot be found..." is an extremely common and ambiguous error, saying that there is a problem, but never where. I was wondering if anyone could tell why this error is occuring. Oh, and I'm on Windows 7 and my PS Version is

PS C:\Users\someone> $PSVersionTable.PSVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
4      0      -1     -1

Any help on this is greatly appreciated.

2 Answers 2

14

New-Object : A parameter cannot be found that matches parameter name 'TypeNamePSObject'

It's not ambiguous at all, the error indicates –TypeNamePSObject is not a known parameter of the New-Object cmdlet.

$object = New-Object –TypeNamePSObject

Should be instead:

$object = New-Object –TypeName PSObject

Note the space delimiting the parameter -TypeName and the value PSObject.

You may use tab completion to discover parameters. In the console, type a cmdlet's name, a space, -, then Tab to cycle through the known parameters. Shift + Tab will reverse the order.

1
-1

Would just like to add: it should be: –MemberType NoteProperty (space in between).

Otherwise, you get this error: Add-Member : A parameter cannot be found that matches parameter name 'MemberTypeNoteProperty'

1
  • This should really be a comment. Dec 29, 2023 at 13:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .