UserLock Documentation
UserLock Documentation
You are here: Reference > UserLock PowerShell > PowerShell script examples

PowerShell script examples

You can find in this section examples of tasks that can be achieved by the console but where a PowerShell script would allow it to be done faster. Most of these tasks should be performed as a Windows scheduled task and so run during non-business hours.

  • Automate the shutdown of workstations (without a session opened):
    Get-UserLockReportedComputer -OnlyWorkstation | where {($_.SessionCount -eq 0) -and ($_.Available)} | Stop-UserLockComputer -Force
  • Automatically deploy the UserLock agent on computers where it is missing:
    Get-UserLockAgentDistribution | where {($_.IsServer -eq 'Workstation') -and ($_.AgentType -eq 'Desktop')-and($_.AgentStatus -eq 'NotInstalled') -and ($_.LastCheckStatus -eq 0)} | Install-UserLockAgent -Force
  • Reboot all workstations with a pending agent installation:
    Get-UserLockAgentDistribution|where {($_.AgentStatus -eq 'installing') -and ($_.IsServer -eq 'workstation')}|Restart-UserLockComputer -Force
  • Send a warning pop-up to all open sessions:
    Get-UserLockInteractiveSession | Send-UserLockPopup -Title 'IT Maintenance' -Message 'The File server is currently restarting. It will be available in 5 minutes. IT Department.' –Force
  • Enforce a UserLock setting ('Welcome Message' in this example) to all your protected users:
    Set-UserLockProtectedAccount -Name * -Type user -Property DisplayWelcomeMessage -Value true –Force
  • Do a massive user sessions reset. Useful after a general power failure, for example:
    Get-UserLockInteractiveSession|where{-not $_.ComputerAvailable}|Reset-UserLockSession –Force