New
#231
OK, I am having trouble with this.
These ALL work in Batch:
Code:set "MAX_Events=2,000" echo - blah EXCEEDS [%MAX_Events%]... PowerShell Write-Host """" "- blah EXCEEDS [%MAX_Events%]...""" PowerShell -ExecutionPolicy Bypass -Command """" "- blah EXCEEDS [%MAX_Events%] ...""" RESULT for ALL THREE: - blah EXCEEDS [2,000] ...
BUT, how do I get the%MAX_Events%
to work in this please ?:
Code:$Security_Log = (Get-WinEvent -ListLog 'Security').RecordCount; ^ if ($Security_Log -gt %MAX_Events%) {Write-Host """`n blah EXCEEDS [%MAX_Events%] ..."""; exit 1} else { ^
I doNOT
want the Script re-written, I just need to know how to get the%MAX_Events%
as a CMD.
I have tried things likecmd.exe /c
etc, but toNO
avail.
Thanks.
EDIT:
This works except the format is lost:
Code:set "MAX_Events=2,000" $Security_Log = (Get-WinEvent -ListLog 'Security').RecordCount; ^ if ($Security_Log -gt """%MAX_Events%""") {Write-Host """`n blah EXCEEDS ["""%MAX_Events%"""] ..."""; exit 1} else { ^ RESULT: blah EXCEEDS [ 2 000]
I know I can use:
Code:$MAX_Events=(2000).ToString('#,##0'); ^ $Security_Log = (Get-WinEvent -ListLog 'Security').RecordCount; ^ if ($Security_Log -gt $MAX_Events) {Write-Host """`n blah EXCEEDS [$MAX_Events] ..."""; exit 1} else { ^
BUT, I want to use the Batch variable%MAX_Events%
so I doNOT
need to hard code the2,000
twice for example.
OR, thinking about it, if it is easier, perhaps use a PS variable and then use it in the Batch !!!
Last edited by Paul Black; 25 Aug 2023 at 15:44.