Scripts/Get-MongoFile.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

<#
.Synopsis
    Gets file paths from the file system snapshot database.
 
.Description
    Requires: Mdbc module
    Server: local
    Database: test
    Collection: files (default)
 
    The script searches for file paths by a regular expression pattern or a
    name. It works with data created by Update-MongoFiles.ps1.
 
.Parameter Pattern
        Regular expression pattern or literal file name.
 
.Parameter CollectionName
        Specifies the collection name. Default: files.
 
.Parameter Name
        Tells that the Pattern is a literal name.
 
.Example
    > Get-MongoFile readme
    Get files which names contain "readme".
 
.Example
    > Get-MongoFile readme.txt -Name
    Get files named "readme.txt"
 
.Link
    Update-MongoFiles.ps1
#>


param
(
    [Parameter(Position=0, Mandatory=$true)][string]$Pattern,
    $CollectionName = 'files',
    [switch]$Name
)

Import-Module Mdbc
Connect-Mdbc . test $CollectionName

if ($Name) {
    $query = New-MdbcQuery Name -IEQ $Pattern
}
else {
    $query = New-MdbcQuery Name -Matches $Pattern, i
}

foreach($_ in Get-MdbcData $query -Property @()) { $_._id }