From b8fcca01a5f43ae7acee10aafbffea55b99d5963 Mon Sep 17 00:00:00 2001 From: aaron Date: Mon, 18 Dec 2023 18:00:56 +0000 Subject: [PATCH] Upload files to "/" --- Add-ADOUToGroup.ps1 | 11 ++++++++++ Check-PageFile.ps1 | 10 +++++++++ Copy-LatestFile.ps1 | 9 ++++++++ Delete-Temp&Sage200Folder.ps1 | 32 ++++++++++++++++++++++++++++ Detect-VSS.ps1 | 40 +++++++++++++++++++++++++++++++++++ 5 files changed, 102 insertions(+) create mode 100644 Add-ADOUToGroup.ps1 create mode 100644 Check-PageFile.ps1 create mode 100644 Copy-LatestFile.ps1 create mode 100644 Delete-Temp&Sage200Folder.ps1 create mode 100644 Detect-VSS.ps1 diff --git a/Add-ADOUToGroup.ps1 b/Add-ADOUToGroup.ps1 new file mode 100644 index 0000000..a90fe20 --- /dev/null +++ b/Add-ADOUToGroup.ps1 @@ -0,0 +1,11 @@ +# Takes all the users from an OU and adds them to a group. + +$OUName = "" # Name of the OU +$GroupName = "" # Name of the Group + +$OU = Get-ADOrganizationalUnit -Filter "Name -like '$OUName'" -Properties DistinguishedName +$OUPath = $OU.DistinguishedName + +$Users = Get-ADUser -Filter * -SearchBase $OUPath | Select-Object + +Add-ADGroupMember -Identity $GroupName -Members $Users diff --git a/Check-PageFile.ps1 b/Check-PageFile.ps1 new file mode 100644 index 0000000..8692895 --- /dev/null +++ b/Check-PageFile.ps1 @@ -0,0 +1,10 @@ +# Checks if the page file is at 90% capacity + +$AutoManaged = (Get-CimInstance Win32_ComputerSystem).AutomaticManagedPagefile +if ($AutoManaged -eq $false){Write-Host "Page file is not Automatically managed by Windows"; exit 0} + +$page = Get-CimInstance Win32_PageFileUsage -Property * + +$threshold = ($page.AllocatedBaseSize * (9/10)) +if ($page.CurrentUsage -gt $threshold){"Page File Threshold reached"; exit 1} +else {"Page File Threshold NOT Reached"; exit 0} diff --git a/Copy-LatestFile.ps1 b/Copy-LatestFile.ps1 new file mode 100644 index 0000000..d6252be --- /dev/null +++ b/Copy-LatestFile.ps1 @@ -0,0 +1,9 @@ +# Looks at the latest file in a given directory and then copies it to a second given directory. + +$targetPath = "" # Source directory +$outputPath = "" # Output directory + +Set-Location $targetPath +$latestFile = (Get-ChildItem -Path $targetPath -Attributes !Directory | Sort-Object -Descending -Property LastWriteTime | Select-Object -First 1) + +Copy-Item -Path $latestFile -Destination $outputPath diff --git a/Delete-Temp&Sage200Folder.ps1 b/Delete-Temp&Sage200Folder.ps1 new file mode 100644 index 0000000..93ff1ed --- /dev/null +++ b/Delete-Temp&Sage200Folder.ps1 @@ -0,0 +1,32 @@ +#Sets Execution Policy to allow script to run +Set-ExecutionPolicy -Scope CurrentUser -Force Unrestricted -Confirm:$False + +#start-sleep -Seconds 10 + +#Sets current user name to varible, converts to string, finds index of "\", adds 1 to get the index of the first character in name +$user = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name +$user.ToString() +$i = $user.IndexOf("\") +$i+=1 + +#Creates blank string varible +$userNew = "" + +#For loop to start at the index of first character of username and end at the length of the username +for ($i; $i -lt $user.Length; $i++) +{ + $userNew = $userNew + $user[$i] #adds the indexed character to new varible +} + +$userNew + +$TempFolder = "C:\Users\"+$userNew+"\AppData\Local\Temp\" +$SageFolder = "C:\Users\"+$userNew+"\AppData\Local\Sage\Sage200\" +Get-ChildItem $TempFolder | Remove-Item -Recurse -Force +Get-ChildItem $SageFolder | Remove-Item -Recurse -Force + +#start-sleep -Seconds 10 + +Set-ExecutionPolicy -Scope CurrentUser -Force Undefined -Confirm:$False + +#start-sleep -Seconds 20 diff --git a/Detect-VSS.ps1 b/Detect-VSS.ps1 new file mode 100644 index 0000000..ce292ec --- /dev/null +++ b/Detect-VSS.ps1 @@ -0,0 +1,40 @@ +# Detects various states of Volume Shadow Copies, Disabled, Enabled with Default schedule, Enabled with custom schedule and Enabled with custom schedule ensuring all disks are enabled. + +$ScheduledTasks = Get-ScheduledTask -TaskName "ShadowCopy*" +$DefaultTasks = Get-ScheduledTask -TaskName "ShadowCopyVolume{*}" +$CustomTasks = Get-ScheduledTask -TaskName "ShadowCopy * drive" + +$CustomTaskLetters = ForEach ($task in $CustomTasks){$task.TaskName[11]} + +$VSS = [PSCustomObject]@{ + enabled = $false + type = $null +} + +$Disks = Get-Volume | Where-Object {$_.DriveType -eq "Fixed"} | Where-Object {$_.DriveLetter -ne $null} | Where-Object {$_.Size -gt 5GB} + +$MissingDrives = ForEach ($letter in $Disks.DriveLetter){if ($letter -notin $CustomTaskLetters){$letter}} + +#No Tasks +if ($ScheduledTasks -eq $null) + {Write-Host "No VSS Tasks"} +#Default Tasks +elseif ($DefaultTasks.State -ne "Disabled") + {Write-Host "Default VSS Tasks Enabled"; $VSS.enabled = $true; $VSS.type = "Default"} +#Default Tasks Disabled and No Custom Tasks +if (($DefaultTasks.State -eq "Disabled") -and ($CustomTasks -eq $null)) + {Write-Host "Default VSS Tasks Disabled and NO Custom VSS Tasks"; $VSS.enabled = $false; $VSS.type = "Default"} +#Default Tasks Disabled and Custom Tasks Enabled +if ((($DefaultTasks.State -eq "Disabled") -or ($DefaultTasks -eq $null)) -and ($CustomTasks -ne $null)) + {Write-Host "Default VSS Tasks Disabled and Custom VSS Tasks Enabled"; $VSS.enabled = $true; $VSS.type = "Custom"} +#Default Tasks Disabled and Custom Tasks Enabled, but not all drives have been enabled +if ($MissingDrives -ne $null) + {Write-Host "Default VSS Tasks Disabled and Custom VSS Tasks Enabled, But Not all Drives are Enabled"; $VSS.enabled = $true; $VSS.type = "Custom, Incomplete"} + + +if ($Host.Version.Major -gt 4){Write-Host $VSS} +elseif ($Host.Version.Major -lt 5){$VSS} + +if ($VSS.enabled -eq $false){exit 1} +elseif ($VSS.type -ne "Custom"){exit 2} +else{exit 0}