Giter Club home page Giter Club logo

ministryofjustice.pfs-onsite-automation's Introduction

PFS On-Site Automation Guidelines

Prerequisites

Powershell V5 + and a client to run it.

Standards

All PowerShell comitted to this repo must meet the following requirements:

  1. All scripts need the header as documented here. This must be present before commit and updated on each commit.

  2. It must be a single script for all Prisons. Variables are defined and discovered within the script. If this is not possible, it must be documented why and be agreed with the team. A example of this

Get-ADComputer -SearchBase 'OU=Laptops,OU=Prisoners,OU=Workstations,OU=WLI,OU=Prisons,DC=WLI,DC=DPN,DC=GOV,DC=UK' -Property Name,lastLogonDate -Filter {lastLogonDate -lt $date} | Set-ADComputer -Enabled $false

Should be changed to

#What domain?

If (($env:USERDOMAIN) -eq "WLI")
{
    $Global:Domain = "WLI"
}
elseif (($env:USERDOMAIN) -eq "BWI")
{
    $Global:Domain = "BWI"
}

Get-ADComputer -SearchBase "OU=Laptops,OU=Prisoners,OU=Workstations,OU=$domain,OU=Prisons,DC=$domain,DC=DPN,DC=GOV,DC=UK" -Property Name,lastLogonDate -Filter {lastLogonDate -lt $date} | Set-ADComputer -Enabled $false
  1. Audit Audit Audit! - We have a requirement to audit as much as possible in a script. The following should be used to keep things consistent.
# PowerShell function - Add-Log
# Author: Rich Dakin
Function Add-Log
        {Param ([string]$logstring)
        $logfile = "D:\AD-Automation\Logfile.txt"
        $date = Get-date
        $Global:date = $date.ToString("dd-MM-yyyy-HH-mm")
        add-content $logfile -value "$date :: $logstring"
        }

Further examples of this is taking a one liner script that cannot be fully audited and breaking it out into more cleaner foreach

Get-ADComputer -SearchBase "OU=Laptops,OU=Prisoners,OU=Workstations,OU=$domain,OU=Prisons,DC=$domain,DC=DPN,DC=GOV,DC=UK" -Property Name,lastLogonDate -Filter {lastLogonDate -lt $date} | Set-ADComputer -Enabled $false

Becomes

$GetComputer  = Get-ADComputer -SearchBase "OU=Laptops,OU=Prisoners,OU=Workstations,OU=$domain,OU=Prisons,DC=$domain,DC=DPN,DC=GOV,DC=UK" -Property Name,lastLogonDate -Filter {lastLogonDate -lt $date}

Foreach ($Computer in $GetComputer)
{
    ###Audit
    Add-log "$Computer is being disabled"
    Set-ADComputer -Identity $Computer -Enabled $False
}
  1. Your script must be able to run everytime. Without throwing errors. Example
New-Item -Path "c:\" -Name "logfiles" -ItemType "directory"

#The second time this script runs it will fail on the directory existing. Thus you must complete a test path and use a IF Statement.

If ((Test-path "c:\Logfiles") -ne $True)

{
    New-Item -path c:\Logfiles -ItemType Directory
}

###Now the script will not fail on the subsequent  runs.
  1. All functions should be documented inline, as shown in point 3.

  2. Code should be self documenting, with comments in the appropriate.

ministryofjustice.pfs-onsite-automation's People

Contributors

richdakin avatar

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.