Additional Script Updates

This commit is contained in:
Andrew Amason
2025-05-19 15:19:36 -04:00
parent ec2b22290a
commit 9c8438d7d1
136 changed files with 1595 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
# Check for low disk space
$freeSpace = (Get-PSDrive -Name C).Free
if ($freeSpace -lt 10GB) {
Write-Output "Low disk space"
exit 1
} else {
Write-Output "Sufficient disk space"
exit 0
}

View File

@@ -0,0 +1,3 @@
# Perform disk cleanup
Start-Process -FilePath "cleanmgr.exe" -ArgumentList "/sagerun:1" -Wait
Write-Output "Disk cleanup performed"

View File

@@ -0,0 +1,24 @@
# Define the inactivity threshold in days
$inactivityThreshold = 90
# Get the current date
$currentDate = Get-Date
# Get all user profiles on the endpoint
$userProfiles = Get-WmiObject -Class Win32_UserProfile | Where-Object { $_.Special -eq $false }
foreach ($profile in $userProfiles) {
# Get the last use time of the profile
$lastUseTime = [Management.ManagementDateTimeConverter]::ToDateTime($profile.LastUseTime)
# Calculate the number of days since the profile was last used
$daysInactive = ($currentDate - $lastUseTime).Days
if ($daysInactive -ge $inactivityThreshold) {
# Exit with code 1 to indicate an issue was detected
exit 1
}
}
# Exit with code 0 to indicate no issues were detected
exit 0

View File

@@ -0,0 +1,24 @@
# Define the inactivity threshold in days
$inactivityThreshold = 90
# Get the current date
$currentDate = Get-Date
# Get all user profiles on the endpoint
$userProfiles = Get-WmiObject -Class Win32_UserProfile | Where-Object { $_.Special -eq $false }
foreach ($profile in $userProfiles) {
# Get the last use time of the profile
$lastUseTime = [Management.ManagementDateTimeConverter]::ToDateTime($profile.LastUseTime)
# Calculate the number of days since the profile was last used
$daysInactive = ($currentDate - $lastUseTime).Days
if ($daysInactive -ge $inactivityThreshold) {
# Log the profile that is inactive
Write-Output "Inactive profile detected: $($profile.LocalPath) - Last used: $lastUseTime"
# Optionally, remove the inactive profile
# Remove-WmiObject -InputObject $profile
}
}

View File

@@ -0,0 +1,23 @@
# Detection Script: Detect_InactiveUsers.ps1
# Define the inactivity threshold in days
$inactivityThreshold = 90
# Get the current date
$currentDate = Get-Date
# Get all user accounts
$userAccounts = Get-LocalUser
foreach ($user in $userAccounts) {
# Check the last logon date
$lastLogonDate = (Get-LocalUser -Name $user.Name).LastLogon
if ($lastLogonDate -lt $currentDate.AddDays(-$inactivityThreshold)) {
Write-Output "Inactive user account detected: $($user.Name)"
exit 1
}
}
Write-Output "No inactive user accounts detected."
exit 0

View File

@@ -0,0 +1,23 @@
# Remediation Script: Remediate_InactiveUsers.ps1
# Define the inactivity threshold in days
$inactivityThreshold = 90
# Get the current date
$currentDate = Get-Date
# Get all user accounts
$userAccounts = Get-LocalUser
foreach ($user in $userAccounts) {
# Check the last logon date
$lastLogonDate = (Get-LocalUser -Name $user.Name).LastLogon
if ($lastLogonDate -lt $currentDate.AddDays(-$inactivityThreshold)) {
# Disable inactive user account
Disable-LocalUser -Name $user.Name
Write-Output "Disabled inactive user account: $($user.Name)"
}
}
Write-Output "Inactive user accounts have been disabled."

View File

@@ -0,0 +1,15 @@
# Detection Script: Detect_LowDiskSpace.ps1
# Define the threshold for low disk space in GB
$thresholdGB = 10
# Get the free space on the system drive
$freeSpaceGB = [math]::Round((Get-PSDrive -Name C).Free / 1GB, 2)
if ($freeSpaceGB -lt $thresholdGB) {
Write-Output "Low disk space detected: $freeSpaceGB GB free"
exit 1
} else {
Write-Output "Sufficient disk space: $freeSpaceGB GB free"
exit 0
}

View File

@@ -0,0 +1,14 @@
# Remediation Script: Remediate_LowDiskSpace.ps1
# Clear temporary files
$TempFolder = "$env:Temp"
Remove-Item "$TempFolder\*" -Recurse -Force -ErrorAction SilentlyContinue
# Clear Windows Update cache
$WindowsUpdateCache = "C:\Windows\SoftwareDistribution\Download"
Remove-Item "$WindowsUpdateCache\*" -Recurse -Force -ErrorAction SilentlyContinue
# Clear Recycle Bin
Clear-RecycleBin -Force -ErrorAction SilentlyContinue
Write-Output "Disk space cleanup completed."

View File

@@ -0,0 +1,24 @@
# Detection Script: Detect_SystemPerformance.ps1
# Define thresholds for high usage
$cpuThreshold = 80
$memoryThreshold = 80
$diskThreshold = 80
# Get current CPU usage
$cpuUsage = Get-Counter '\Processor(_Total)\% Processor Time' | Select-Object -ExpandProperty CounterSamples | Select-Object -ExpandProperty CookedValue
# Get current memory usage
$memoryUsage = (Get-Counter '\Memory\% Committed Bytes In Use').CounterSamples.CookedValue
# Get current disk usage
$diskUsage = Get-Counter '\LogicalDisk(_Total)\% Disk Time' | Select-Object -ExpandProperty CounterSamples | Select-Object -ExpandProperty CookedValue
# Check if any usage exceeds the threshold
if ($cpuUsage -gt $cpuThreshold -or $memoryUsage -gt $memoryThreshold -or $diskUsage -gt $diskThreshold) {
Write-Output "High system resource usage detected: CPU=$cpuUsage%, Memory=$memoryUsage%, Disk=$diskUsage%"
exit 1
} else {
Write-Output "System resource usage is within acceptable limits: CPU=$cpuUsage%, Memory=$memoryUsage%, Disk=$diskUsage%"
exit 0
}

View File

@@ -0,0 +1,20 @@
# Remediation Script: Remediate_SystemPerformance.ps1
# Clear temporary files
$TempFolder = "$env:Temp"
Remove-Item "$TempFolder\*" -Recurse -Force -ErrorAction SilentlyContinue
# Clear Windows Update cache
$WindowsUpdateCache = "C:\Windows\SoftwareDistribution\Download"
Remove-Item "$WindowsUpdateCache\*" -Recurse -Force -ErrorAction SilentlyContinue
# Optimize disk space
Start-Process -FilePath "cleanmgr.exe" -ArgumentList "/sagerun:1" -NoNewWindow -Wait
# Defragment the disk (if not SSD)
$diskType = Get-PhysicalDisk | Where-Object MediaType -eq "HDD"
if ($diskType) {
Optimize-Volume -DriveLetter C -Defrag -Verbose
}
Write-Output "System performance optimization tasks completed."

View File

@@ -0,0 +1,32 @@
# Detection Script: Detect_UserProfiles.ps1
# Define the size threshold in MB
$sizeThresholdMB = 500
# Get all user profiles
$userProfiles = Get-WmiObject -Class Win32_UserProfile | Where-Object { $_.Special -eq $false }
# Initialize flag for non-compliance
$nonCompliant = $false
foreach ($profile in $userProfiles) {
# Check if the profile is corrupted
if ($profile.Status -ne 0) {
Write-Output "Corrupted profile detected: $($profile.LocalPath)"
$nonCompliant = $true
}
# Check if the profile size exceeds the threshold
$profileSizeMB = [math]::Round((Get-ChildItem -Path $profile.LocalPath -Recurse | Measure-Object -Property Length -Sum).Sum / 1MB, 2)
if ($profileSizeMB -gt $sizeThresholdMB) {
Write-Output "Profile size exceeds threshold: $($profile.LocalPath) - Size: $profileSizeMB MB"
$nonCompliant = $true
}
}
if ($nonCompliant) {
exit 1
} else {
Write-Output "All user profiles are compliant."
exit 0
}

View File

@@ -0,0 +1,26 @@
# Remediation Script: Remediate_UserProfiles.ps1
# Define the size threshold in MB
$sizeThresholdMB = 500
# Get all user profiles
$userProfiles = Get-WmiObject -Class Win32_UserProfile | Where-Object { $_.Special -eq $false }
foreach ($profile in $userProfiles) {
# Check if the profile is corrupted
if ($profile.Status -ne 0) {
# Remove corrupted profile
Remove-WmiObject -InputObject $profile
Write-Output "Removed corrupted profile: $($profile.LocalPath)"
}
# Check if the profile size exceeds the threshold
$profileSizeMB = [math]::Round((Get-ChildItem -Path $profile.LocalPath -Recurse | Measure-Object -Property Length -Sum).Sum / 1MB, 2)
if ($profileSizeMB -gt $sizeThresholdMB) {
# Remove large profile
Remove-WmiObject -InputObject $profile
Write-Output "Removed large profile: $($profile.LocalPath) - Size: $profileSizeMB MB"
}
}
Write-Output "User profile remediation tasks completed."

View File

@@ -0,0 +1,31 @@
## Device Performance
### Get-DiskCleanup
[Link](https://github.com/AntoPorter/Intune-Remediations/tree/main/DevicePerformance/Get-DiskCleanup)
- **Detection**: Checks for low disk space on C: (requires modification based on your requirements).
- **Remediation**: Performs Disk Cleanup if low disk space is detected.
### Get-InactiveUsers-EntraID
[Link](https://github.com/AntoPorter/Intune-Remediations/tree/main/DevicePerformance/Get-InactiveUsers-EntraID)
- **Detection**: Checks for all inactive profiles (Including Entra ID) based on a specified time period (requires modification based on your requirements).
- **Remediation**: Removes inactive profiles if detected.
### Get-InactiveUsers-Local
[Link](https://github.com/AntoPorter/Intune-Remediations/tree/main/DevicePerformance/Get-InactiveUsers-Local)
- **Detection**: Checks for any local inactive profiles based on a specified time period (requires modification based on your requirements).
- **Remediation**: Removes inactive profiles if detected.
### Get-LowDiskSpace
[Link](https://github.com/AntoPorter/Intune-Remediations/tree/main/DevicePerformance/Get-LowDiskSpace)
- **Detection**: Checks for low disk space on C: (requires modification based on your requirements).
- **Remediation**: Clears notable Temp locations if low disk space is detected.
### Get-SystemPerformance
[Link](https://github.com/AntoPorter/Intune-Remediations/tree/main/DevicePerformance/Get-SystemPerformance)
- **Detection**: Checks the % usage of CPU/Memory/Disk (requires modification based on your requirements).
- **Remediation**: Clears notable Temp locations and performs optimization tasks if usage is above the specified threshold.
### Get-UserProfiles
[Link](https://github.com/AntoPorter/Intune-Remediations/tree/main/DevicePerformance/Get-UserProfiles)
- **Detection**: Checks for large user profile sizes (requires modification based on your requirements).
- **Remediation**: Clears notable Temp locations if large profiles are detected. Also reports and clears corrupted profiles as required.