commit 8248d694aa7049f4d3780a1b422d35a85fcdbf82 Author: izebra Date: Mon Jun 5 11:51:38 2023 -0700 first commit diff --git a/activitystats.ps1 b/activitystats.ps1 new file mode 100644 index 0000000..90909a5 --- /dev/null +++ b/activitystats.ps1 @@ -0,0 +1,87 @@ +#Zebra - 5/21/2023 +#Activity Status tracker script. Queries activity status of the currently logged in user. +#Works for both Console and Terminal Services sessions + +Add-Type @" +using System; +using System.Diagnostics; +using System.Runtime.InteropServices; + +public static class UserInput { + [DllImport("user32.dll")] + static extern bool GetLastInputInfo(ref LASTINPUTINFO plii); + + [StructLayout(LayoutKind.Sequential)] + struct LASTINPUTINFO { + public uint cbSize; + public uint dwTime; + } + + public static TimeSpan GetIdleTime() { + LASTINPUTINFO lastInput = new LASTINPUTINFO(); + lastInput.cbSize = (uint)Marshal.SizeOf(lastInput); + if (!GetLastInputInfo(ref lastInput)) { + throw new Exception("Unable to get last input time."); + } + return TimeSpan.FromMilliseconds(Environment.TickCount - lastInput.dwTime); + } +} +"@ + +$windowsEdition = (Get-CimInstance Win32_OperatingSystem).Caption + + + if ($windowsEdition -match "Pro" -or $windowsEdition -match "Enterprise" -or $windowsEdition -match "Server") { + Write-Host "Windows Pro or Enterprise Edition detected." + + $session = @(qwinsta /server:localhost 2> $null | Select-String "Active") + + if ($session) { + #$idleTime = [UserInput]::GetIdleTime() + #$session = $session | Where-Object { $_ -notmatch 'console' } + $localSession = $session | Where-Object { $_ -match 'console' } + $rdpSession = $session | Where-Object { $_ -match 'rdp' } + if ($localSession) { + $username = ($localSession -split "\s+")[2] + #$sessionId = ($localSession -split "\s+")[3] + $idleTime = [UserInput]::GetIdleTime() + if ($idleTime.TotalMinutes -gt 15) { + $lastActive = (Get-Date).add(-$idleTime) + Write-Host "($username) is logged in via Console and inactive since $lastActive." + } else { + Write-Host "($username) is currently logged in via Console and active." + } + } elseif ($rdpSession) { + $username = ($rdpSession -split "\s+")[2] + # $sessionId = ($rdpSession -split "\s+")[3] + $idleTime = [UserInput]::GetIdleTime() + if ($idleTime.TotalMinutes -gt 15) { + $lastActive = (Get-Date).add(-$idleTime) + Write-Host "($username) is logged in via RDP and inactive since $lastActive." + } else { + Write-Host "($username) is currently logged in via RDP and active." + } + } + + } else { + Write-Host "No user is currently logged on." + } + } + else { + + Write-Host "Windows Pro or Enterprise not detected." + + $username = (Get-WmiObject -Class Win32_ComputerSystem).UserName + + if ($username) { + $idleTime = [UserInput]::GetIdleTime() + if ($idleTime.TotalMinutes -gt 15) { + $lastActive = (Get-Date).add(-$idleTime) + Write-Host "($username) is logged in and inactive since $lastActive" + } else { + Write-Host "($username) is currently logged on and active." + } + } else { + Write-Host "No user is currently logged on." + } +} \ No newline at end of file diff --git a/battery-status.ps1 b/battery-status.ps1 new file mode 100644 index 0000000..25f1b8e --- /dev/null +++ b/battery-status.ps1 @@ -0,0 +1,31 @@ +#zebra- 6/2/2023 +#Script to get current battery percentage & status + +$computerSystem = Get-WmiObject -Class Win32_ComputerSystem +$computerModel = $computerSystem.Model +$systemType = $computerSystem.PCSystemType +#check if machine is a Laptop +$isLaptop = ($systemType -eq 2) + +if ($isLaptop) { + #Get Battery current stats + $battery = Get-WmiObject -Class Win32_Battery + $batteryPercentage = $battery.EstimatedChargeRemaining + $batteryStatus = $battery.BatteryStatus + $finalStatus = "Battery status: Unknown" + + switch ($batteryStatus) { + 1 { $finalStatus = "Discharging" } + 2 { $finalStatus = "Charging" } + 3 { $finalStatus = "Fully charged" } + 4 { $finalStatus = "Low"} + 5 { $finalStatus = "Critical"} + 6 { $finalStatus = "Charging and high" } + 7 { $finalStatus = "Charging and low" } + 8 { $finalStatus = "Charging and critical"} + 9 { $finalStatus = "Undefined"} + 10 { $finalStatus = "Partially charged" } + default { $finalStatus = "Battery status: Unknown" } + } + Write-Host "$batteryPercentage% - $finalStatus" +} \ No newline at end of file diff --git a/disable-touchscreen.ps1 b/disable-touchscreen.ps1 new file mode 100644 index 0000000..16d97d5 --- /dev/null +++ b/disable-touchscreen.ps1 @@ -0,0 +1,2 @@ +#Zebra - Disables all touch screens +Get-PnpDevice | Where-Object {$_. FriendlyName -like '*touch screen*'} | Disable-PnpDevice -Confirm:$false \ No newline at end of file diff --git a/lastreboot.ps1 b/lastreboot.ps1 new file mode 100644 index 0000000..43bd639 --- /dev/null +++ b/lastreboot.ps1 @@ -0,0 +1,26 @@ +#* = Required +#* -days (Max days) +# +#-returncode (Prints return code 0 if the last bootup time is less than 4 days than the current date, and 1 if it's over 4 days.) + + +[CmdletBinding()] +param ( + [switch]$returncode, + [int]$days = 4 +) + +$os = Get-WmiObject Win32_OperatingSystem +$lastBootupTime = $os.ConvertToDateTime($os.LastBootUpTime) +$daysSinceLastBootup = (Get-Date) - $lastBootupTime | select -ExpandProperty Days + +$lastBootupTimeFormatted = $lastBootupTime.ToString("MM/dd/yy hh:mm:ss") + +if ($daysSinceLastBootup -lt $days) { + Write-Host "$lastBootupTimeFormatted" + if ($returncode) { exit 0 } +} +else { + Write-Host "$lastBootupTimeFormatted" + if ($returncode) { exit 1 } +} \ No newline at end of file diff --git a/officeversion.ps1 b/officeversion.ps1 new file mode 100644 index 0000000..4f19932 --- /dev/null +++ b/officeversion.ps1 @@ -0,0 +1,29 @@ +#zebra +#Gets current Microsoft Office Version + +$ReportedVersion = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Office\ClickToRun\Configuration" -Name "VersionToReport" +$Channel = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Office\ClickToRun\Configuration" -Name "CDNBaseUrl" | Select-Object -Last 1 +$CloudVersionInfo = Invoke-RestMethod 'https://clients.config.office.net/releases/v1.0/OfficeReleases' +$UsedChannel = $cloudVersioninfo | Where-Object { $_.OfficeVersions.cdnBaseURL -eq $channel } + +if ($UsedChannel.latestversion -eq $ReportedVersion) { + Write-Host "Up to date. $($ReportedVersion) - Channel: $($UsedChannel.Channel) " + exit 0 +} +else { + Write-Host "Not up to date, $($UsedChannel.Channel) Channel. Check if version is still supported" + $OurVersion = $CloudVersionInfo.OfficeVersions | Where-Object -Property legacyVersion -EQ $ReportedVersion + if ($OurVersion.endOfSupportDate -eq "0001-01-01T00:00:00Z") { + Write-Host "Not up to date: $($ReportedVersion) - Latest: $($UsedChannel.latestVersion)" + exit 0 + } + if ($OurVersion.endOfSupportDate) { + Write-Host "Out of date: $($ReportedVersion) - End of Support: $($OurVersion.endOfSupportDate) - Latest: $($UsedChannel.latestVersion)" + exit 1 + } + else { + Write-Host "Unsupported: $($ReportedVersion) - Latest: $($UsedChannel.latestVersion)." + #$CloudVersionInfo.OfficeVersions + exit 1 + } +} \ No newline at end of file diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..d629216 --- /dev/null +++ b/readme.md @@ -0,0 +1,10 @@ +Conglomeration of PowerShell scripts to be used in tandem with an RMM
+ + diff --git a/spacesniffer-deploy.ps1 b/spacesniffer-deploy.ps1 new file mode 100644 index 0000000..725be8d --- /dev/null +++ b/spacesniffer-deploy.ps1 @@ -0,0 +1,24 @@ +#zebra 5/23/23 +#Deploys and runs SpaceSniffer. Defaults to C: Drive +#args: -drive + +[CmdletBinding()] +param ( + [string]$drive = "C" +) +$folderPath = "C:\Ktemp\tools" +$downloadUrl = "https://git.izebra.xyz/Mirrored_Repos/SpaceSniffer/raw/branch/main/SpaceSniffer.exe" +$filePath = "C:\Ktemp\tools\SpaceSniffer.exe" + +if(!(Test-Path -Path $folderPath -PathType Container)) +{ + New-Item -ItemType Directory -Path $folderPath | Out-Null +} +# Check if the file already exists +if (-not (Test-Path $filePath)) { + # Download the file using Invoke-WebRequest + [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 + Invoke-WebRequest -Uri $downloadUrl -OutFile $filePath +} + +C:\Ktemp\tools\SpaceSniffer.exe /S scan $drive export "SpaceSniffer binary snapshot" "C:\Ktemp\tools\SpaceSniffer-$(get-date -f yyyy-MM-dd-hh-mm-ss).sns" autoclose \ No newline at end of file