Skip to content

Instantly share code, notes, and snippets.

@daisyUniverse
Created April 29, 2025 19:43
Show Gist options
  • Save daisyUniverse/f2a73d2f32bcd6c55e5911deb7713d36 to your computer and use it in GitHub Desktop.
Save daisyUniverse/f2a73d2f32bcd6c55e5911deb7713d36 to your computer and use it in GitHub Desktop.
# Wake Room
# Leverage SCCM to wake any room
# Robin Universe [D]
# 04 . 29 . 25
param(
[string]$SiteCode = "",
[string]$FQDN = ""
)
# Some basic user verification stuff
$cred = Get-Credential -Credential "$(whoami)" # We will probably not need this bit, but let's pretend it's a bit of security theatre
$isAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (!$isAdmin) { gui-warn "You are not an administrator. Go away."; return }
# Let's start the party by trying to connect to the CMSite straight away..
$breacrumb = pwd
function Connect-CMSite {
Set-Location "C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin"
Import-Module .\ConfigurationManager.psd1
if (!(Test-Path "$SiteCode:\")){ New-PSDrive -Name "$SiteCode" -PSProvider CMSite -Root $FQDN }
Set-Location "$SiteCode:\"
}
# If the SCCM client is installed here, we're probably on a tech machine. Proceed locally...
$OnTechMachine = Test-Path "C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin"
if ($OnTechMachine) {
Connect-CMSite
$target = RoomPrompt
Invoke-WakeUp $target
} else {
$target = RoomPrompt
$techcomputer = gui-input "We need to PSRemote into a machine with SCCM installed for this to work. Enter Tech Computer name"
Invoke-RemoteWakup $target $techcomputer
}
# A few helper functions to make the basic GUI stuff a bit more tidy, we have to do this AFTER connecting to the CMSite.
Add-Type -AssemblyName Microsoft.VisualBasic; Add-Type -AssemblyName System.Windows.Forms
function gui-warn([string]$message){ $resp = [System.Windows.Forms.MessageBox]::Show($message, (pwd), [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Warning); return $resp}
function gui-input([string]$message){ $name = [Microsoft.VisualBasic.Interaction]::InputBox( $message, (pwd) ); return $name }
# Ask user to input a room to wake. basically acts as a wildcard, so try not to let them enter something goofy...
function RoomPrompt {
$target = gui-input "What room should I wake up? Leave blank to just attempt to wake the room you're in"
if ($target = "" ) { gui-warn "No target defined. this would break things. Bailing..." ; return }
if ($target.Length -lt 4 ) { gui-warn "That's a little short for a room name (ie G208)... Looks fishy. Please don't wake up the entire floor." ; return }
if ($target -contains "*" ) { gui-warn "Please DONT use wildcards. We're already gonna be doing that at the end of your query" ; return }
return $target
}
function Invoke-Wakeup([string]$target) {
$Computers = (Get-CMDevice -Name "$target*").Name
$confirm = gui-warn "Computers to wake:`n`n$Computers"
if ($confirm -eq "OK") {
foreach ($com in $Computers){ # danger zone
Invoke-CMClientAction -ActionType ClientNotificationWakeUpClientNow -DeviceName $com
gui-warn "You have cast $($Computers.legth) darts of magic missile for 1d4+1 Force damage each"
}
}
}
function Invoke-RemoteWakup([string]$target, [string]$techcomputer){
if ($name -eq "") {gui-warn "No input detected. bailing..."; return}
# We don't have the luxury of piecing this out when run in a remote session, so we kinda just have to blind fire and hope for the best
try {
Invoke-Command -Credential $cred -ComputerName $name -ScriptBlock {
Set-Location "C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin"
Import-Module .\ConfigurationManager.psd1
if (!(Test-Path "$SiteCode:\")){ New-PSDrive -Name "$SiteCode" -PSProvider CMSite -Root $FQDN }
Set-Location "$SiteCode:\"
$Computers = (Get-CMDevice -Name "$target*").Name
foreach ($com in $Computers){ # danger zone
Invoke-CMClientAction -ActionType ClientNotificationWakeUpClientNow -DeviceName $com
}
}
} catch {
gui-warn "Failed to connect to your computer: $_"
}
}
Set-Location $breacrumb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment