#212890 - 2017-11-16 08:35 PM
Why I'm unable to verify the output correctly ?
|
Patrick99
Fresh Scripter
Registered: 2016-02-19
Posts: 14
Loc: Belgium
|
Hello, I would like to verify the outcome of the Powershell command in an txt file , however It looks like I cannot, can someone help me? script:
Shell "Powershell Set-ExecutionPolicy RemoteSigned"
Shell "Powershell get-ExecutionPolicy > c:\temp\PSSec.txt"
$fileToCheck = "c:\temp\PSSec.txt"
$stringToFind = "RemoteSigned"
If Exist($fileToCheck)
$stringFound = 0
$fileContents = Split(CreateObject("Scripting.FileSystemObject").OpenTextFile($fileToCheck, 1, Not 1).ReadAll, @CRLF)
For Each $line in $fileContents
If InStr($line, $stringToFind)
$stringFound = 1
EndIf
Next
If $stringFound
MessageBox("Status OK ! ", "ICT - INFO", 64, 1)
Else
MessageBox("Status NOT OK ! ", "ICT - INFO", 64, 1)
EndIf
EndIf
Edited by ShaneEP (2017-11-17 10:25 PM) Edit Reason: put code in code tags
|
Top
|
|
|
|
#212891 - 2017-11-16 10:43 PM
Re: Why I'm unable to verify the output correctly ?
[Re: Patrick99]
|
ShaneEP
MM club member
Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
|
I can't get it to fail on my computer. Maybe some security issue with the FSO? Stupied question...But you have verified the PS part is working, and the text is in the text file?
Have you tried using native kix functions only?
$fileToCheck = "c:\temp\PSSec.txt"
$stringToFind = "RemoteSigned"
If Exist($fileToCheck)
$stringFound = 0
$fh = FreeFileHandle()
$nul = Open($fh, $fileToCheck)
While @error = 0
$line = ReadLine($fh)
If InStr($line, $stringToFind)
$stringFound = 1
EndIf
Loop
If $stringFound
$nul = MessageBox("Status OK ! ", "ICT - INFO", 64, 3)
Else
$nul = MessageBox("Status NOT OK ! ", "ICT - INFO", 64, 3)
EndIf
EndIf
|
Top
|
|
|
|
#212893 - 2017-11-17 07:26 AM
Re: Why I'm unable to verify the output correctly ?
[Re: ShaneEP]
|
Patrick99
Fresh Scripter
Registered: 2016-02-19
Posts: 14
Loc: Belgium
|
Hello Shane, The issue is not changing the status but checking the status in the txt file. The file contains just "Restricted" same as your output, so when you change the $stringToFind = "RemoteSigned" to $stringToFind = "Restricted",do you get it right now? For meself it didn't work, however I do the same with powershell it get the status OK. Why is the status NOK with kix? does it work for you?
|
Top
|
|
|
|
#212897 - 2017-11-17 10:33 PM
Re: Why I'm unable to verify the output correctly ?
[Re: Patrick99]
|
ShaneEP
MM club member
Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
|
The PS seems to be creating some kind of funky text file. If I add code to display the lines as they're read, it displays this...
|
Top
|
|
|
|
#212898 - 2017-11-17 10:38 PM
Re: Why I'm unable to verify the output correctly ?
[Re: ShaneEP]
|
ShaneEP
MM club member
Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
|
If I use the code I posted above, which uses built in Kix functions. It still gets funky results, but at least usable. It shows...
So try this code, and see if it gets you where you need.
Shell "Powershell Set-ExecutionPolicy RemoteSigned"
Shell "Powershell get-ExecutionPolicy > c:\temp\PSSec.txt"
$fileToCheck = "c:\temp\PSSec.txt"
$stringToFind = "RemoteSigned"
If Exist($fileToCheck)
$stringFound = 0
$fh = FreeFileHandle()
$nul = Open($fh, $fileToCheck)
While @error = 0
$line = ReadLine($fh)
$text = $text + $line
Loop
If InStr($text, $stringToFind)
$stringFound = 1
Endif
If $stringFound
$nul = MessageBox("Status OK ! ", "ICT - INFO", 64, 3)
Else
$nul = MessageBox("Status NOT OK ! ", "ICT - INFO", 64, 3)
EndIf
Endif
Edited by ShaneEP (2017-11-17 10:39 PM)
|
Top
|
|
|
|
#212900 - 2017-11-18 01:59 PM
Re: Why I'm unable to verify the output correctly ?
[Re: ShaneEP]
|
Patrick99
Fresh Scripter
Registered: 2016-02-19
Posts: 14
Loc: Belgium
|
Many thanks Shane, you are great!
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 507 anonymous users online.
|
|
|