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.
It's not ambiguous at all, the error indicates
–TypeNamePSObject
is not a known parameter of theNew-Object
cmdlet.Should be instead:
Note the space delimiting the parameter
-TypeName
and the valuePSObject
.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.
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'