Thanks for the pointers Is it just me getting old or do newer scripting languages always look so much more complicated at first glance? :-)
Cheers, JR On 16 April 2013 17:14, Michael B. Smith <[email protected]> wrote: > This should help. “msg” is just a function that logs all of its > arguments to a text file.**** > > ** ** > > function tmpFileName**** > > {**** > > msg $L_Function**** > > msg "tmpFileName: enter"**** > > ** ** > > [string] $strFile = ( Join-Path $Env:Temp ( Get-Random ) ) > + ".txt"**** > > if( ( Test-Path -Path $strFile -PathType Leaf ) )**** > > {**** > > msg "Old temporary file was found: > $strFile - I will delete it"**** > > rm $strFile -EA 0**** > > if( $? )**** > > {**** > > msg "...file was deleted"* > *** > > }**** > > else**** > > {**** > > msg "...couldn't delete > file, error: $($error[0].ToString())"**** > > }**** > > }**** > > ** ** > > msg "tmpFileName: exit, filename = $strFile"**** > > return $strFile**** > > }**** > > ** ** > > function Get-ExitCodeAndOutput**** > > {**** > > ###**** > > ### see comments for Get-ExitCode**** > > ###**** > > ### We are also going to retrieve the standard output from > the legacy application.**** > > ###**** > > ### This is a PowerShell v2.0 version of Get-ExitCode > which also includes**** > > ### the redirection of output and error streams to > temporary files.**** > > ###**** > > ** ** > > msg $L_Function**** > > msg "Get-ExitCodeAndOutput: enter"**** > > ** ** > > $stderrFile = tmpFileName**** > > $stdoutFile = tmpFileName**** > > $exit = -1**** > > ** ** > > $filename, $arguments = $args**** > > msg "Get-ExitCodeAndOutput: filename = $filename, > arguments = $arguments"**** > > ** ** > > $process = Start-Process -FilePath $filename -Argument > $arguments -NoNewWindow `**** > > -RedirectStandardError $stderrFile > -RedirectStandardOutput $stdoutFile -PassThru**** > > ** ** > > if( $process )**** > > {**** > > msg "Get-ExitCodeAndOutput: please wait..." > **** > > ** ** > > $process.WaitForExit()**** > > $exit = $process.ExitCode**** > > if( $exit -eq $null )**** > > {**** > > msg "exit is null"**** > > $exit = 0**** > > }**** > > ** ** > > $process.Close()**** > > $process.Dispose()**** > > }**** > > else**** > > {**** > > msg "Get-ExitCodeAndOutput: the process > did not start"**** > > }**** > > ** ** > > $process = $null**** > > ** ** > > $script:LegacyStdErr = gc $stderrFile -EA 0**** > > $script:LegacyStdOut = gc $stdoutFile -EA 0**** > > ** ** > > rm $stderrFile -EA 0**** > > rm $stdoutFile -EA 0**** > > ** ** > > msg "Get-ExitCodeAndOutput: exit, exit = > $($exit.ToString())"**** > > return $exit**** > > }**** > > ** ** > > *From:* James Rankin [mailto:[email protected]] > *Sent:* Tuesday, April 16, 2013 11:54 AM > > *To:* NT System Admin Issues > *Subject:* Re: PowerShell noob help**** > > ** ** > > The problem I've got is that I have to call out of the console I am using > to the command script file. If I write the same task in PowerShell, well > the console natively supports it so it's easier for people to use it.**** > > **** > > I will have a bash around with that command to grab the output, cheers**** > > On 16 April 2013 16:38, Michael B. Smith <[email protected]> wrote:*** > * > > Start-Process gives you complete control over executing a separate task.** > ** > > **** > > If you don’t need complete control, but just the text output, you don’t > need to do anything.**** > > **** > > $result = CTXCliOS.exe ^ | find “ClientOS”**** > > **** > > You can make it more PowerShell, if you want, but there isn’t much value > in doing so. (If you want to start talking about into making it an > “Enterprise Class” script, then that changes things dramatically. Ask Web > about the things I’ve shown him the last year.) J**** > > **** > > *From:* James Rankin [mailto:[email protected]] > *Sent:* Tuesday, April 16, 2013 11:06 AM > *To:* NT System Admin Issues > *Subject:* PowerShell noob help**** > > **** > > I've got a batch script I've been using for a while to identify the > flavour of client connecting to a XenApp or XenDesktop session. It uses an > executable called CTXCliOS.exe**** > > **** > > Basically this is the batch**** > > **** > > *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***** > > **** > > I'm sure you get the picture.**** > > **** > > 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)? What's > the command to call an outside executable (I can't seem to dig it up, but I > am on a network where just about every helpful site is blocked by the web > filter, so don't be too hard on me, please!)**** > > **** > > Thanks in advance,**** > > **** > > > > -- > *James Rankin* > Technical Consultant (ACA, CCA, MCTS) > 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] > 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**** > > > > > -- > *James Rankin* > Technical Consultant (ACA, CCA, MCTS) > 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] > 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 > -- *James Rankin* Technical Consultant (ACA, CCA, MCTS) 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] with the body: unsubscribe ntsysadmin
