PSGalleryStats.psm1

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
61
62
63
64
65
66
67
68
<#
.Synopsis
   Get Powershell Gallery Statistics for the specified Date.
.DESCRIPTION
   Get List of published modules on the specified date.
.EXAMPLE
    PS C:\> Get-PSGalleryStatistics -Date "3/21/2019" -ov Stats
    Summary Details
    ------- -------
    There were 23 modules published on 3/21/2019. {@{Author=Aaron Parker; ModuleName=VcRedist; Version=1.5.2.100; Publis...
     
    PS C:\>$Stats.summary
There were 23 modules published on 3/21/2019.
#>

function Get-PSGalleryStatistics
{
    [CmdletBinding(SupportsShouldProcess=$true, 
                  PositionalBinding=$false,
                  ConfirmImpact='Medium')]
    [Alias('psgs')]
    Param
    (
        # Date for which you want to get stats
        [Parameter(ValueFromPipeline=$true,
                   ValueFromPipelineByPropertyName=$true, 
                   Position=0)]
        [ValidateNotNullOrEmpty()]
        [datetime]$Date=(Get-Date).AddDays(-1)
    )

    Begin
    {
    }
    Process
    {
        if ($pscmdlet.ShouldProcess("date $Date"))
        {
            $PublishedToday=0
            $ModuleArrayList=New-Object System.Collections.ArrayList
            $AvailableModules=find-module -Name *
             foreach($m in $AvailableModules){
     
                 if($m.PublishedDate.Date -eq $Date.Date ){
                  $PublishedToday++
                  $prop=@{
                    Author=$($m.Author)
                    ModuleName=$($m.Name)
                    Version=$($m.Version)
                    PublishedDate=$($m.PublishedDate)
                  }
                  $ModuleObj=New-Object -TypeName psobject -Property $prop | Select-Object Author,ModuleName,Version,PublishedDate
                  $ModuleArrayList.Add($ModuleObj) | Out-Null
      
                 }

             }
        }
        $ResultObjProps=@{
            Summary="There were $PublishedToday modules published on $($Date.GetDateTimeFormats()[0])."
            Details=$ModuleArrayList
        }
        $ResultObj=New-Object -TypeName psobject -Property $ResultObjProps
        $ResultObj
    }
    End
    {
    }
}