![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Command & variable substitution Hello I have the following problem while creating a script which contains the following line: 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 Specs![]() |
| | #2 (permalink) |
| | Re: Command & variable substitution 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 Fanatic http://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: > > 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 Specs![]() |
| | #3 (permalink) |
| | 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: 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 Specs![]() |
| | #4 (permalink) |
| | Re: Command & variable substitution Does this work? $strWMIClassName = "win32_process" get-wmiobject -class $strWMIClassName If so, check your script. What's the output of echo $strWMIClassDescription each iteration? I suggest to download PowerGUI. It has a built-in script debugger you can use to find what's wrong. You can download it at: http://powergui.org/downloads.jspa ----- 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: >>> > ;-) > > 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 Specs![]() |
| | #5 (permalink) |
| | Re: Command & variable substitution BTW, why all the description and comments stuff when all you need is to query with WMI? Woudn't it be much simpler to store your WMI class names in CSV file and avoid the parsing? ----- 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: >>> > ;-) > > 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 Specs![]() |
| | #6 (permalink) |
| | 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: >>> > ;-) > > 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 Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Re: Command substitution | PowerShell | |||
| How to perform variable substitution in powershell? | PowerShell | |||
| Stumped by variable substitution | PowerShell | |||
| RE: Execute from command line with environment variable in path | PowerShell | |||
| Execute from command line with environment variable in path | PowerShell | |||