-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGet-ESSearchResult.ps1
46 lines (45 loc) · 1.74 KB
/
Get-ESSearchResult.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
function Get-ESSearchResult {
[CmdletBinding()]
[Alias("search")]
Param
(
#searchterm
[Parameter(Mandatory=$true, Position=0)]
$SearchTerm,
#openitem
[switch]$OpenItem,
[switch]$CopyFullPath,
[switch]$OpenFolder,
[switch]$AsObject
)
$esPath = 'E:\Program Files\Everything\es.exe'
if (!(Test-Path (Resolve-Path $esPath).Path)){
Write-Warning "Everything commandline es.exe could not be found on the system please download and install via http://www.voidtools.com/es.zip"
exit
}
$result = & (Resolve-Path $esPath).Path $SearchTerm
if($result.Count -gt 1){
$result = $result | Out-GridView -PassThru
}
foreach($record in $result){
switch ($PSBoundParameters){
{ $_.ContainsKey("CopyFullPath") } { $record | clip }
{ $_.ContainsKey("OpenItem") } { if (Test-Path $record -PathType Leaf) { & "$record" } }
{ $_.ContainsKey("OpenFolder") } { & "explorer.exe" /select,"$(Split-Path $record)" }
{ $_.ContainsKey("AsObject") } { $record | Get-ItemProperty }
default { $record | Get-ItemProperty |
select Name,DirectoryName,@{Name="Size";Expression={$_.Length | Get-FileSize }},LastWriteTime
}
}
}
}
filter Get-FileSize {
"{0:N2} {1}" -f $(
if ($_ -lt 1kb) { $_, 'Bytes' }
elseif ($_ -lt 1mb) { ($_/1kb), 'KB' }
elseif ($_ -lt 1gb) { ($_/1mb), 'MB' }
elseif ($_ -lt 1tb) { ($_/1gb), 'GB' }
elseif ($_ -lt 1pb) { ($_/1tb), 'TB' }
else { ($_/1pb), 'PB' }
)
}