$result = $clientOS.SubString( 9 )

From: James Rankin [mailto:[email protected]]
Sent: Tuesday, April 16, 2013 12:08 PM
To: NT System Admin Issues
Subject: Re: PowerShell noob help

I've managed to use Select-String to get my output and my variable, it's 
splitting the variable up (from something like ClientOS=ThinOS_Wyse down to 
just ThinOS_Wyse) that's frying my brain now. I really should take reference 
publications kindly provided by people down the years with me onto sites :-(

All fun!
On 16 April 2013 17:00, Ben Scott 
<[email protected]<mailto:[email protected]>> wrote:
On Tue, Apr 16, 2013 at 11:05 AM, James Rankin 
<[email protected]<mailto:[email protected]>> wrote:
> for /f "tokens=2 delims==" %%a in ('CTXCliOS.exe ^| find "ClientOS"') do set
> ClientOS=%%a& call :SET
>
> goto :eof
>
> :SET
>
> reg add HKCU\Software\Custom /v ClientOS /t REG_SZ /d %ClientOS% /f
> goto :eof
>
> What I'm wondering is what format do I use to convert this to PowerShell
> (which will avoid having to invoke a separate command script file)?
  Only work will convert a script to another language.  :)

> What's the command to call an outside executable
  Nominally, just write out the command on a line, same as a batch
file or *nix shell script.  However, if the external executable needs
to be quoted (e.g., file name or path contains spaces), you need to
prefix the command line with an ampersand (&).  Otherwise PowerShell
treats it as a string.  Kind of a wart on what's generally a much
cleaner language.  You can always specify & if you want.

  I believe you want something like:

$match = & CTXCliOS.exe | Select-String -Pattern 'ClientOS\s+(.+)'
if($match) {
        $clientOS = <then a miracle occurs>
        Set-ItemProperty -Path 'HKCU:\Software\Custom' -Name ClientOS -Value 
$clientOS
}

  I'm having trouble figuring out how to get the regexp capture out of
the $match object returned by Select-String though.  Get-Member leads
me to believe I should be able to do something with

        $match.Matches[0].Groups

but it seems to descend into some kind of recursive nightmare at that
point that makes me believe I'm missing something more fundamental.

-- Ben

~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to 
[email protected]<mailto:[email protected]>
with the body: unsubscribe ntsysadmin



--
James Rankin
Technical Consultant (ACA, CCA, MCTS)
http://appsensebigot.blogspot.co.uk<http://appsensebigot.blogspot.co.uk/>

~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to 
[email protected]<mailto:[email protected]>
with the body: unsubscribe ntsysadmin

~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to [email protected]
with the body: unsubscribe ntsysadmin

Reply via email to