Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

evaluate date/time from file - count instances of line 1 week back

$
0
0

ok, not the best title but I'll try & explain.

I want to:

1. log username that logs on to PC

2. log time of login

3. write this info to a file

4. open file, count number of times the same user logged on to PC going back 1 week

5. if count equal or greater than 10, do stuff.

right now I've got this:

$user=[Environment]::UserName $pcName=[Environment]::MachineName $time = get-Date ##ModelType Query $modelType = Get-WmiObject Win32_ComputersystemProduct | Select-Object -Property Version ##Modeltype.version is the one we want $var1 = $user $var2 = $pcName $var3 = $ModelType.Version ##test the variables $var1 $var2 $var3 $Time #write to text file - Username and append $outfile="C:\tmp\LoggedInUsers.txt" Write-output "Login Time = $Time", "Username = $var1" | out-File $outfile -append

$LogStats = Get-Content C:\tmp\LoggedInUsers.txt

Example of the content of $logstats:

ogin Time = 01/15/2014 14:46:27
Username = mrt
Login Time = 01/15/2014 14:46:31
Username = mrt
Login Time = 01/15/2014 14:46:35
Username = mrt
Login Time = 01/15/2014 14:46:39
Username = mrt

so it should look for "Username" and grab what's next to the '='

and the same for login time.

then go back 1 week from Today and count username instances.

Any help will be greatly appreciated.


Kindest regards, Martin


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>