Skip to content

Instantly share code, notes, and snippets.

@jarnaldich
Created June 6, 2017 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jarnaldich/67296c892cde9f9c5bbe9d7ccac97ee9 to your computer and use it in GitHub Desktop.
Save jarnaldich/67296c892cde9f9c5bbe9d7ccac97ee9 to your computer and use it in GitHub Desktop.
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