Added PCMonitor.ps1 to fix last commit. Oopsie!
This commit is contained in:
parent
4c7146890a
commit
e60cd96bc6
46
Private/PCMonitor.ps1
Normal file
46
Private/PCMonitor.ps1
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
function Invoke-Monitor {
|
||||
param(
|
||||
[string[]] $comps
|
||||
)
|
||||
# Ask to notify
|
||||
# Initialize computer sessions
|
||||
|
||||
}
|
||||
|
||||
class WatchDog {
|
||||
[string]$Hostname
|
||||
[PSSession]$Session
|
||||
[string]$LastUser
|
||||
WatchDog() { $this.Init(@{})}
|
||||
WatchDog([hashtable]$Properties) { $this.Init($Properties)}
|
||||
WatchDog([string]$Hostname) { $this.Init(@{Hostname = $Hostname})}
|
||||
[void] Init([hashtable]$Properties){
|
||||
foreach ($prop in $Properties.Keys) {
|
||||
$this.$prop = $Properties.$prop
|
||||
}
|
||||
}
|
||||
# Returns true if a value was updated
|
||||
[bool] Update() {
|
||||
$old = $this
|
||||
if ((Test-Connection -ComputerName $this.Hostnmae -Count 1)) {
|
||||
$this.Session = $null
|
||||
return -not ($old.Session)
|
||||
}
|
||||
if (-not ($this.Session)) {
|
||||
$this.Session = New-PSSession -ComputerName $this.Hostname -SessionOption (New-PSSessionOption -NoMachineProfile)
|
||||
}
|
||||
$this.LastUser = $(Invoke-Command -Session $this.Session {Get-ComputerInfo}).CSUserName
|
||||
if($null -eq $this.LastUser){
|
||||
|
||||
$this.LastUser = (Invoke-Command -Session $this.Session -ScriptBlock {Get-Process Explorer -IncludeUsername | Where-Object { $_.Username -notlike "*SYSTEM" }} ).Username
|
||||
|
||||
if($null -ne $this.LastUser){
|
||||
$this.LastUser = "$($this.LastUser) (RDP/Inactive)"
|
||||
}
|
||||
else{
|
||||
$this.LastUser = $null
|
||||
}
|
||||
}
|
||||
return (($this.Session -ne $old.Session) -or ($this.LastUser -ne $old.LastUser))
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue