-
Notifications
You must be signed in to change notification settings - Fork 52
/
Test-Path2.ps1
60 lines (53 loc) · 1.58 KB
/
Test-Path2.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
function Test-Path2 {
<#
.Synopsis
Fce slouží ke zjištění, zdali existuje zadaná cesta.
.Description
.PARAMETER $ComputerName
seznam stroju u kterych zjistim prihlasene uzivatele
.PARAMETER $path
Parametr určující jaká cesta se bude testovat.
.EXAMPLE
test-path2 $hala -p C:\temp
#>
[CmdletBinding()]
param (
[Parameter(Mandatory=$true,Position=0,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,HelpMessage="zadej jmeno stroje/ů")]
[Alias("c","CN","__Server","IPAddress","Server","Computer","Name","SamAccountName")]
[String[]] $ComputerName
,
[Parameter(Mandatory=$true,Position=1,HelpMessage="zadej cestu např.: C:\TEMP")]
[Alias("p")]
[string] $path
)
BEGIN {
# adresa ke kontrole
$path = $path -replace ":", "$" -Replace("`"","")
# nazev souboru
$filename = $path.substring($path.lastindexofany("\") +1 )
$AsyncPipelines = @()
$pool = Get-RunspacePool 20
$scriptblock = {
param($Computer,$Path)
if (Test-Connection -ComputerName $computer -Count 1 -quiet -ErrorAction SilentlyContinue) {
If(test-Path "\\$computer\$path") {
write-output "na $computer $filename nalezen"
} else {
write-output "na $computer $filename nenalezen"
}
} else {
write-output "$computer nepingá"
}
}
}
PROCESS {
foreach ($computer in $ComputerName) {
$AsyncPipelines += Invoke-Async -RunspacePool $pool -ScriptBlock $ScriptBlock -Parameters $Computer,$Path
}
}
END {
Receive-AsyncResults -Pipelines $AsyncPipelines -ShowProgress
}
}
# NASTAVENI ALIASU
Set-Alias tp test-path2