On Tue, Apr 16, 2013 at 11:05 AM, James Rankin <[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]
with the body: unsubscribe ntsysadmin