# encoding: ascii # api: powershell # title: Set-RandomFile # description: Creates random file with extension which has assosiation (just for fun). # version: 0.1 # type: function # author: greg zakharov # license: CC0 # function: Set-RandomFile # x-poshcode-id: 4611 # x-archived: 2013-11-22T23:55:50 # x-published: 2013-11-16T15:44:00 # # #requires -version 2.0 function Set-RandomFile { param( [Parameter(Mandatory=$true, Position=0)] [String]$Path, [Parameter(Position=1)] [ValidateRange(0, 31)] [Int32]$Length = 7 ) begin { $ext = cmd /c assoc | % {if ($_ -match '=\w+' -and $_ -notmatch '.\d+=') {$_.Split('=')[0]}} $itm = -join ([GUID]::NewGuid().Guid -replace '-', '')[0..$Length] } process { $rnd = Get-Random -max ($ext.Length - 1) } end{ if (Test-Path $Path) { [void](ni -p $Path -n $($itm + $ext[$rnd]) -t File -fo) } } }