WMI Helper V6 Import Error
-
Wednesday, October 31, 2012 12:40 AM
When I try to import this module I get the following error:
Missing expression after unary operator '-'.
At C:\Documents and Settings\User\My Documents\WindowsPowerShell\Modules\HSGMImoduleV6.psm1:310 char:10
+ - <<<< ExpandProperty Qualifiers |
+ CategoryInfo : ParserError: (-:Sting) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorID : MissingExpressionAfterOperator
Import-Module : The specified module 'HSGMImoduleV6' was not loaded because no valid module file was found in any module directory.
At line:1 car:14
+ import-module <<< -name HGMImoduleV6
+ CategoryInfo InvalidArgument: (:) [Import-Module], ParameterbindingException
+ FullyQualifiedErrorID : NameParameterNotFound,Microsoft.Powershell.Commands.ImportModuleCommand
The actual line looks like this:
[wmiclass]$class = "\\{0}\{1}:{2}" -f $computer,$namespace,$class
$class.Properties |
Select-object @{Name="PropertyName";Expression={$_.name}} `
-ExpandProperty Qualifiers |
Where-object {$_.Name -eq "key"} |
ForEach-Object {$_.PropertyName}
Hi, I like clean computers :-p
- Edited by mrhobbeys Wednesday, October 31, 2012 6:15 AM
All Replies
-
Wednesday, October 31, 2012 9:53 AM
Try to replace this with one line:
Select-object @{Name="PropertyName";Expression={$_.name}} ` -ExpandProperty Qualifiers |
...
and see if this helps
Also, there is known bug with expandproperty that it throws error when property is null
You can try to replace it with | foreach-object {$_.quailfiers}
-
Wednesday, October 31, 2012 10:27 AM
Also, there is known bug with expandproperty that it throws error when property is null
You can try to replace it with | foreach-object {$_.quailfiers}
Interesting. I didn't know this was considered a bug, but a major design error. In fact, to avoid this, rather use dot-notation, because this doesn't return an error:
I'm not sure if this is a new feature of Powershell V3. Can you confirm?Get-ChildItem | Select-Object -ExpandProperty junk # Results in errors (Get-ChildItem).junk # Returns $null
(Get-ChildItem).name # Returns names
Grant Ward, a.k.a. Bigteddy
-
Wednesday, October 31, 2012 10:49 AM
Sorry for being not specific. It is bug for V2, fixed in v3
- Marked As Answer by Bill_StewartMicrosoft Community Contributor, Moderator Thursday, December 20, 2012 11:36 PM
-
Wednesday, October 31, 2012 4:29 PM
Thank you, I tried this now I can import but I get the following error when I try to run the function I am trying to use.
Select-Object : A positional parameter cannot be found that accepts argument ' -ExpandProperty'.
At C:\Documents and Settings\Spencer\My Documents\WindowsPowerShell\Modules\HSGMImoduleV6\HSGMImoduleV6.psm1:307 char:1
4
+ Select-object <<<< @{Name="PropertyName";Expression={$_.name}} ` -ExpandProperty Qualifiers |
+ CategoryInfo : InvalidArgument: (:) [Select-Object], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SelectObjectCommandI was trying to run: Get-WmiKey win32_product
I'm trying to figure this out: http://blogs.technet.com/b/heyscriptingguy/archive/2011/12/14/use-powershell-to-find-and-uninstall-software.aspx
***EDIT
I might have got it. I will post back after I have messed with this a while.
Hi, I like clean computers :-p
- Edited by mrhobbeys Wednesday, October 31, 2012 4:34 PM
-
Thursday, November 01, 2012 12:56 PM
You should remove '`' character. this indicates that command continues on next line but when you puts whole command in a one line it's breaking code

