View Single Post
Old 01-09-2008   #3 (permalink)
Chris


 
 

Re: Command & variable substitution

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].IndexOf($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}....
>
Quote:

> > Has anyone of you an idea how to solve this problem?
>
Quote:

> > Thanks
>
Quote:

> > Chris
My System SpecsSystem Spec