Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Sample Code for Blog Post on Porting Unix Philosophy To Windows
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