Created
June 6, 2017 16:18
-
-
Save jarnaldich/67296c892cde9f9c5bbe9d7ccac97ee9 to your computer and use it in GitHub Desktop.
Sample Code for Blog Post on Porting Unix Philosophy To Windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Sample-Count-Files { | |
[CmdletBinding()] | |
param( | |
# The file pattern to count | |
[Parameter(Mandatory=$true, | |
Position=0)] | |
[string]$pattern, | |
# Name of the log file | |
[Parameter(Mandatory=$true, | |
Position=1)] | |
[string]$logfile, | |
# Seconds interval between samples | |
[Parameter(Mandatory=$true, | |
Position=2)] | |
[int]$seconds) | |
While($true) { | |
sleep $seconds; | |
$cnt = (dir $pattern).Count; | |
$d = Get-Date; | |
$d.ToString("yyyy-MM-dd HH:mm:ss") + "`t$cnt" | Out-File $logfile -encoding ascii -Append -ob 0 | |
} | |
} | |
function Tick { | |
[CmdletBinding()] | |
Param([Parameter(Mandatory=$true, Position=0)][int]$Seconds) | |
Process { | |
while($true) { | |
Start-Sleep -Seconds $Seconds | |
Get-Date | |
} | |
} | |
} | |
function Count { | |
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory=$true, Position=0)] | |
[string]$Pattern, | |
[Parameter(Mandatory=$true, Position=1, ValueFromPipeline=$true)] | |
$Time | |
) | |
Process { | |
[PSCustomObject]@{ | |
Time=$Time; | |
Files= $(dir $Pattern).Count | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment