Very much a newbie to PowerShell but have experience writing shell scripts (unsure if commands can be linked to one another). I am trying to write a script where I want to view a log file and get a count of a number of expired rows. In shell it would look something like this
Could you please choose a little more descriptive subject next time? 99.9% of the questions asked here are questions about PowerShell.
In my experience it does not make that much sense to āmigrateā or ātranslateā shell scripts into PowerShell one command by one because PowerShell uses rich and powerful objects instead of stupid text.
So of course your task is quite easily achievable with PowerShell as well. You could use
to find the desired strings or patterns in a given file.
Thank you so much Olaf! Apologies for the simple header I will ensure it is more suitable next time!
The log files I want to view are hosted on another server (Linux Server to be exact) I can view these via a URL or obviously logging into the server itself, what would you suggest be the best way? Also how would this affect the command?
Well as usual ā¦ it depends. What would you like to do with the information you get? It will probably run faster when you run it locally but the result will be the same.
Hmmm ā¦ I donāt have any experience with linux server but Iām sure there is something like a task scheduler. If I recall it right itās been named cron job or cron daemon in the past. Why donāt you run this task locally on that remote server and only read the result remotely from the local machine?
Unfortunately it isnāt my server so can only read into it, like I said there is a URL to view the logs so I could read via the web browser if easier?
Apologies Olaf donāt mean to be confusing and misleading.
So I canāt write anything on the server as it isnāt my server so I have to write the script remotely. I can connect into the server e.g. with SSH to view the log filesā¦ Or I can connect through a web browser and view the log files that way (I have uploaded a screenshot).
So I want to write a script to connect to the server or webpage and get a count of how many have āExpiredā
You still could ask the owner of the server to cooperate.
Iāve read about the possibility to use SSH with PowerShell to connect to Linux server but Iām not familiar with it. You may search for more info about this topic either here or the PowerShellGallery or maybe StackOverflow.
You could try to download the file via Invoke-WebRequest and process it locally.
Then I tried to get it to print out just those with expired but unfortunately not getting any luck. Using an if command I am able to print out 1 if it finds expired which is a starting point but sadly not what I am after
Thanks so much for that great help - as I only want to see this as a count I tried to change the .RawContent to .Count but no output, how would I show this as a count?