Coder Social home page Coder Social logo

get-latestwindowspatchingdate's People

Contributors

guyver1wales avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

get-latestwindowspatchingdate's Issues

Some Improvments

Hi Kieran,
Could I suggest to you some improvments ?

  1. Useless var

$results = foreach ($i in $servers) {
$serverName = $i ...

Replace by
$results = foreach ($iServerName in $servers) {...

  1. Error Handling
    You use Try... catch statements, it's a goog thing but perhaps before all the Try... catch you could run a "Test-Connection" test. If the computer is not Online, The "Try" operation failed (of course), but the "catch" operation too.

  2. Var declaration
    You could define $ScriptPath using $PSScriptRoot automatic variable.
    Why using foreach ($_ in $scriptPaths), there is only one path.
    The code for this section could be :

$ScriptPath = $PSScriptRoot
$ReportsPath = Join-Path -Path $ScriptPath -ChildPath "REPORTS"

if (-not (Test-Path -Path $ReportsPath) )
    {
    New-Item -Path $ReportsPath -ItemType Directory
    }
  1. Output
    Perhaps, the output file could be timestamped in the name ?
    Another suggestion : You could add a param section at the beginning of the script, like in the advanced functions. In this section you could define some vars like
    PeriodTime : Max period to report. This, to custom as user would like the "90 Days hard coded". A default value of 90 could be set.
    Export : ParameterSet values could be AllTime (this corresponds to your $FinalResult), MaxDays (this corresponds to your 3 Months Report), AllTime&PeriodTime

Something like the following :

#Beginning of the script
Param
    (
        # Max Period to Report
        [Parameter()]
        [int]
        $PeriodTime = 90

        # Report type to generate
        [Parameter(ParameterSetName='Parameter Set 1')]
        [ValidateSet("AllTime", "PeriodTime", "AllTimeAndPeriodTime")]
        [String]
        $Export = "AllTimeAndPeriodTime"
   )

#... script Code
#region Export
switch ($Export)
{
    'AllTime' {
                $finalResults | 
                    Export-Csv -Path "$reports\latest-windows-update_At_$(Get-Date -f "yyyy-MM-dd").csv" -NoTypeInformation
              }
    'PeriodTime'{ 
                $PeriodReport = $finalResults | 
                    Where-Object { $_.SystemFilesDate -lt "$((Get-Date).AddDays(-$PeriodTime))" }
                $PeriodReport | 
                    Export-Csv -Path "$reports\$($PeriodTime)months-windows-update_At_$(Get-Date -f "yyyy-MM-dd").csv" -NoTypeInformation
                }
    'AllTimeAndPeriodTime' {}
}

Like this, the user could use the script

  • without passing any parameter ==> Script use default values
  • Passing some parameters ==> Script use the value for parameters
    i.e.
    .\MyScript.ps1 -Export PeriodTime
    .\MyScript.ps1 -Export PeriodTime -PeriodTime 120
    .\MyScript.ps1 -PeriodTime 120

Hope these suggestions are helpful
Regards
Olivier

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.