View Single Post
Old 01-09-2008   #6 (permalink)
Shay Levi


 
 

Re: Command & variable substitution

Can you try this:

############ .\WMIList.config ###########

Win32_Fan;Blubb
#Win32_Share;Blubber
Win32_Share;Blubber
#Win32_Share;Blubber

############ .\WMIList.config ###########



cat C:\Scripts\temp\WMIList.config | where {$_.substring(0,1) -ne "#"} |
foreach {
$strWMIClassName = $_.substring(0,$_.indexOf(";"))
$strWMIClassName
#get-wmiobject -class $strWMIClassName
}


# output #
Win32_Fan
Win32_Share


-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic


Quote:

> On 9 Jan., 13:17, Shay Levi <n...@xxxxxx> wrote:
>
Quote:

>> It works fine on v1 & v2
>>
>> $strWMIClassName = "win32_process"
>> get-wmiobject -class $strWMIClassName
>> You didn't include the $strWMIClassName assignment in your post,
>> check that it's not $null
>>
>> -----
>> Shay Levi
>> $cript Fanatichttp://scriptolog.blogspot.com
>> Hebrew weblog:http://blogs.microsoft.co.il/blogs/scriptfanatic
Quote:

>>> Hello I have the following problem while creating a script which
>>> contains the following line:
>>>
> Yes I haven't post it, because i didnt wan to post the whole script
> ;-)
>
> I have verified that the var is not null. it contains as example the
> value Win32_Fan...
>
> here my whole script...
>
> ###
> # Script options
> #
> $boolDebug = $true
> #
> $strConfigFile = ".\WMIList.config"
> #
> $strCommentSign = "#"
> #
> $strDelimSign = ";"
> # End script options
> ###
> $intConfigCounter = 0
>
> # Clear the screen
> cls
> # Read the configuration and exclude the comments
> $strConfig = cat $strConfigFile | where
> {$_.StartsWith($strCommentSign) -eq $false -and $_.Length -gt 0}
> # Iterate all config lines (entries)
> while ($intConfigCounter -lt $strConfig.Length) {
> # Get the description of the current WMI Class out of the
> config
> # For this need all signs after the delim sign are stored
> $strWMIClassDescription =
> $strConfig[$intConfigCounter].Substring($strConfig[$intConfigCounter].
> IndexOf($strDelimSign)
> +1)
>
> # DEBUG
> echo $strWMIClassDescription
> # Get the name of the current WMI Class out of the config
> # For this need remove the description, caused by this just
> the name will return
> $strWMIClassName =
> $strConfig[$intConfigCounter].Remove($strConfig[$intConfigCounter].Ind
> exOf($strDelimSign)
> +1, $strWMIClassDescription.Length)
>
> # DEBUG
> echo $strWMIClassName
> get-wmiobject -class $strWMIClassName
> # Raise counter
> $intConfigCounter = $intConfigCounter + 1
> } # end while iterate all config entries
>
> The script access a config file which contains as example:
>
> # Comment
> Win32_Fan;Blubb
> Win32_Share;Blubber
Quote:
Quote:

>>> Script line:
>>> get-wmiobject -class $strWMIClassName
>>> Error description:
>>> At xxx 1:74 char:15
>>> + get-wmiobject <<<< -class $strWMIClassName
>>> As you can see the var is not substituted. I have tried all the ways
>>> I
>>> do know from unix shells and so on how to substitute line $($var), `
>>> $var`, ${var}....
>>> Has anyone of you an idea how to solve this problem?
>>>
>>> Thanks
>>>
>>> Chris
>>>

My System SpecsSystem Spec