<# .SYNOPSIS RDP Drive Redirection test for Create/Delete redirected files .DESCRIPTION Run file system operations to verify creation/deletion files on a redirected drive .PARAMETER Path Specifies a path to the tested remote folder, e.g. \\tsclient\c\test .PARAMETER NamePrefix Specifies a prefix which is added to tested file names, e.g. 1_ .PARAMETER Iterations Specifies a numer of iterations for the test bunch #> [CmdletBinding(PositionalBinding=$false)] Param( [Parameter(Mandatory)][string] $Path, [string] $NamePrefix = '', [string] $Iterations = 1 ) function Log($message) { Write-Host $message } class Test { [string] $mainDir [string] $file1 [string] $file2 [string] $file3 static [string] $fileType = 'file' static [string] $directoryType = 'directory' static [void] CreateItem([string] $type, [string] $path) { $item = New-Item -Path $path -ItemType $type if (!$item) { Throw ("Failed to create {0} '{1}'" -f $type, $path) } Log(("{0} '{1}' has been created" -f $type, $path)) } static [void] DeleteFile([string] $path) { Remove-Item -Path $path Log(("Item '{0}' has been deleted" -f $path)) } static [void] CreateFile([string] $path) { [Test]::CreateItem([Test]::fileType, $path) } static [void] CreateDirectory([string] $path) { [Test]::CreateItem([Test]::directoryType, $path) } static [void] DeleteDirectory([string] $path) { [string[]] $items = @() (Get-ChildItem -Path $path) | ForEach-Object { $items += $_.Name } if ($items.count -gt 0) { Throw(("Unexpected list of items ({0}) in folder '{1}'" -f "$items", $path)) } [Test]::DeleteFile($path) if (Test-Path -Path $path) { Throw ("Failed to delete main directory {0}" -f $path) } } Test([string] $path, [string] $namePrefix) { $this.mainDir = ("{0}\{1}folder" -f $path, $namePrefix) $this.file1 = ("{0}\{1}file1" -f $this.mainDir, $namePrefix) $this.file2 = ("{0}\{1}file2" -f $this.mainDir, $namePrefix) $this.file3 = ("{0}\{1}file3" -f $this.mainDir, $namePrefix) if (!(Test-Path -Path $path)) { [Test]::CreateDirectory($path) } if (Test-Path -Path $this.mainDir) { Remove-Item -Path $this.mainDir -Force -Recurse -Confirm:$false } } [void] Run() { [Test]::CreateDirectory($this.mainDir) [Test]::CreateFile($this.file2) [Test]::CreateFile($this.file1) [Test]::DeleteFile($this.file2) [Test]::DeleteFile($this.file1) [Test]::DeleteDirectory($this.mainDir) [Test]::CreateDirectory($this.mainDir) $file = [IO.File]::Create($this.file3, 1, 'DeleteOnClose') $file.Close() Log("Wait for deletion completed...") while (Test-Path -Path $this.file3) { Start-Sleep -Milliseconds 10 } Log(("File {0} has been deleted by DELETE_ON_CLOSE" -f $this.file3)) [Test]::DeleteDirectory($this.mainDir) } } $test = [Test]::new($Path, $NamePrefix) for ($i = 1; $i -le $Iterations; $i++) { echo "=======================" echo "Run #$i" $result = $test.Run() }