first commit

This commit is contained in:
izebra 2023-06-05 11:51:38 -07:00
commit 8248d694aa
7 changed files with 209 additions and 0 deletions

87
activitystats.ps1 Normal file
View File

@ -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."
}
}

31
battery-status.ps1 Normal file
View File

@ -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"
}

2
disable-touchscreen.ps1 Normal file
View File

@ -0,0 +1,2 @@
#Zebra - Disables all touch screens
Get-PnpDevice | Where-Object {$_. FriendlyName -like '*touch screen*'} | Disable-PnpDevice -Confirm:$false

26
lastreboot.ps1 Normal file
View File

@ -0,0 +1,26 @@
#* = Required
#* -days <int> (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 }
}

29
officeversion.ps1 Normal file
View File

@ -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
}
}

10
readme.md Normal file
View File

@ -0,0 +1,10 @@
Conglomeration of PowerShell scripts to be used in tandem with an RMM<br />
<ul>
<li>activitystats.ps1 - Returns Activity Status of User in console (Run as User)</li>
<li>battery-status.ps1 - Returns Battery Status of Laptops in console</li>
<li>disable-touchscreen.ps1 - Disables Touch screen devices</li>
<li>lastreboot.ps1 - Returns last reboot date/time in console</li>
<li>officeversion.ps1 - Returns MS Office version in console</li>
<li>spacesniffer-deploy.ps1 - Downloads SpaceSniffer and generates a SpaceSniffer snapshot file of desired drive.</li>
</ul>

24
spacesniffer-deploy.ps1 Normal file
View File

@ -0,0 +1,24 @@
#zebra 5/23/23
#Deploys and runs SpaceSniffer. Defaults to C: Drive
#args: -drive <char>
[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