Public/Get-AUPackages.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
# Author: Miodrag Milic <miodrag.milic@gmail.com>
# Last Change: 12-Nov-2016.

<#
.SYNOPSIS
    Get AU packages
 
.DESCRIPTION
 
    Returns list of directories that have update.ps1 script in them and package name
    doesn't start with the '_' char (unpublished packages, not considered by Update-AUPackages
    function).
 
    Function looks in the directory pointed to by the global variable $au_root or, if not set,
    the current directory.
 
.EXAMPLE
    gau p*
 
    Get all automatic packages that start with 'p' in the current directory.
 
.EXAMPLE
    $au_root = 'c:\packages'; lsau 'cpu-z*','p*','copyq'
 
    Get all automatic packages in the directory 'c:\packages' that start with 'cpu-z' or 'p' and package which name is 'copyq'.
#>

function Get-AUPackages( [string[]] $Name ) {
    $root = $global:au_root
    if (!$root) { $root = $pwd }

    ls $root\*\update.ps1 | % {
        $packageDir = gi (Split-Path $_)

        if ($Name -and $Name.Length -gt 0) {
            $m = $Name | ? { $packageDir.Name -like $_ }
            if (!$m) { return }
        }

        if ($packageDir.Name -like '_*') { return }
        $packageDir
    }
}

Set-Alias gau  Get-AuPackages
Set-Alias lsau Get-AuPackages