diff --git a/FuncGoToEnd.ps1 b/FuncGoToEnd.ps1 new file mode 100644 index 0000000..46cc4e2 --- /dev/null +++ b/FuncGoToEnd.ps1 @@ -0,0 +1,14 @@ +function GoToEnd($timer) +{ + # Restore location + Pop-Location + + $timer.Stop() + $runTime = "$($timer.Elapsed)" + + [Log]::new("Script Runtime full: $runtime").Out() + [Log]::new("The End.").Out() + + # Stops log + [Log]::new((Stop-Transcript)).Out() +} \ No newline at end of file diff --git a/GetUserObjectSID.ps1 b/GetUserObjectSID.ps1 new file mode 100644 index 0000000..a42d567 --- /dev/null +++ b/GetUserObjectSID.ps1 @@ -0,0 +1,11 @@ +[CmdLetBinding()] +Param( + [Parameter(Mandatory=$true, valueFromPipeLine = $true)] + [String]$SamAccountName, + + [Parameter(Mandatory=$false)] + [String]$Domain = (Get-ADDomain).NetBiosName +) +$ObjectId = [String]($Domain + "\" + $SamAccountName) +$account = New-Object System.Security.Principal.NTAccount $ObjectId +$account.Translate([System.Security.Principal.SecurityIdentifier]).Value \ No newline at end of file diff --git a/SetDateAndTimeInformation.ps1 b/SetDateAndTimeInformation.ps1 new file mode 100644 index 0000000..97ab87f --- /dev/null +++ b/SetDateAndTimeInformation.ps1 @@ -0,0 +1,6 @@ +#region Time / Date Info + $DateRef = [datetime]::Now + $Timer = [system.diagnostics.stopwatch]::StartNew() + $dateSimple = $DateRef.toString("yyyyMMdd") + $dateStamped = $DateRef.ToString("yyyyMMdd.HHmmss") +#endregion#> \ No newline at end of file diff --git a/SetEnd.ps1 b/SetEnd.ps1 new file mode 100644 index 0000000..8af6924 --- /dev/null +++ b/SetEnd.ps1 @@ -0,0 +1,11 @@ +# Restore location +Pop-Location + +$timer.Stop() +$runTime = "$($timer.Elapsed)" + +[Log]::new("Script Runtime full: $runtime").Out() +[Log]::new("The End.").Out() + +# Stops log +[Log]::new((Stop-Transcript -ErrorAction SilentlyContinue)).Out() \ No newline at end of file diff --git a/SetFiles.ps1 b/SetFiles.ps1 new file mode 100644 index 0000000..1f49531 --- /dev/null +++ b/SetFiles.ps1 @@ -0,0 +1,28 @@ +# SetFilesCLass.ps1 is mandatory +[CmdLetBinding()] +Param( + [Parameter(Mandatory=$true, valueFromPipeLine = $true)] + [String]$_scriptLocation +) + +#region files and paths + # Determine script location for PowerShell + if ( $_ScriptLocation -eq $null -or $_ScriptLocation -eq "" ) + { + $_ScriptLocation = "." + } + [Files]::base = $_scriptlocation + + # Set Files retention (7 is by default) + [Files]::FilesToKeep = 3 + + # Determine current location + Push-Location + $_savWorkDir = Get-Location + + # Force WorkDir to be the same as Script location + if ($_savWorkDir.Path -ne [Files]::Base) + { + Set-Location ([Files]::Base) + } +#endregion#> \ No newline at end of file diff --git a/SetPaths.ps1 b/SetPaths.ps1 new file mode 100644 index 0000000..e6c3942 --- /dev/null +++ b/SetPaths.ps1 @@ -0,0 +1,17 @@ +# SetFilesCLass.ps1 is mandatory +[CmdLetBinding()] +Param( + [Parameter(Mandatory=$true, valueFromPipeLine = $true)] + [String]$_ScriptFullName +) + +#region paths + $Paths = @{ + Logs = [Files]::new("Logs") + Results = [Files]::new("Results").SetName($dateSimple + "." + 'Result.csv').Finalize() + Script = [Files]::new().SetName($_ScriptFullName).Finalize() + Bck = [Files]::new("Backups").SetName($dateSimple + "." + 'Backup.csv').Finalize() + Roll = [Files]::new("RollBacks").SetName($dateSimple + "." + 'RollBack.ps1').Finalize() + } + $null = $Paths.Logs.SetName($dateStamped + "." + ( [System.IO.Path]::GetFileNameWithoutExtension($_ScriptFullName) ).ToLower() + '.log').Finalize() +#endregion#> \ No newline at end of file diff --git a/SetStart.ps1 b/SetStart.ps1 new file mode 100644 index 0000000..8a2a4eb --- /dev/null +++ b/SetStart.ps1 @@ -0,0 +1,30 @@ +#region Prep + + $rawSpace="`n`n`n`n`n`n" + + $_paramEC = @{ + path = ".\" + Encoding = "UTF8" + Delimiter = ';' + NoTypeInformation = $true + Force = $true + } + + # To prevent any running transcript + try { + Stop-Transcript -ErrorAction SilentlyContinue | out-null + } + catch [System.InvalidOperationException] + { + $Error.Clear() + } + + clear-host + + # Create a margin so you can see what is on the screen + Write-host $rawSpace + + [Log]::new((Start-Transcript -Path ($Paths.Logs.FullPath))).Out() + [Log]::Release() + +#endregion#> \ No newline at end of file