[CmdletBinding()] param( [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [string]$UNCPATH, [ValidateSet('LastWriteTime', 'DateString')] [string]$MonitorType = 'LastWriteTime', [ValidateNotNullOrEmpty()] [string]$Filter, [ValidateRange(1, 2147483647)] [int]$TimeSpan = 1, # Days relative to today: 0 = today, -1 = yesterday. [int]$DaysOffset = 0 ) #$cred = Get-Credential #$cred | Export-Clixml -Path $HOME\mycred.xml $ErrorActionPreference = 'Stop' $exitCode = 0 $connected = $false try { $cred = Import-Clixml -Path $HOME\mycred.xml New-PSDrive -Name Share -PSProvider FileSystem ` -Root $UNCPATH -Credential $cred -ErrorAction Stop | Out-Null $connected = $true $monitorParameters = @{ MonitorType = $MonitorType FolderPath = 'Share:\' DaysOffset = $DaysOffset } if ($PSBoundParameters.ContainsKey('Filter')) { $monitorParameters.Filter = $Filter } if ($PSBoundParameters.ContainsKey('TimeSpan')) { $monitorParameters.TimeSpan = $TimeSpan } $result = & (Join-Path $PSScriptRoot 'FileNumMonitor.ps1') @monitorParameters } catch { $exitCode = 1 Write-Error -ErrorRecord $_ -ErrorAction Continue } finally { if ($connected) { try { Remove-PSDrive -Name Share -Force -ErrorAction Stop } catch { $exitCode = 1 Write-Error -ErrorRecord $_ -ErrorAction Continue } } } if ($exitCode -eq 0) { $result } exit $exitCode