Functions/GenXdev.Windows/Set-MonitorPowerOff.cs
|
// ################################################################################
// Part of PowerShell module : GenXdev.Windows // Original cmdlet filename : Set-MonitorPowerOff.cs // Original author : René Vaessen / GenXdev // Version : 3.28.2026 // ################################################################################ // Copyright (c) 2026 René Vaessen / GenXdev // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // ################################################################################ using System.Management.Automation; namespace GenXdev.Windows { [System.ComponentModel.Description(@" .SYNOPSIS Turns off power to all connected monitors. .DESCRIPTION Uses Windows API calls to send a power-off signal to all connected monitors. This is equivalent to pressing the physical power button on your monitors. The monitors will enter power saving mode but can be awakened by moving the mouse or pressing a key. .EXAMPLE ```powershell Set-MonitorPowerOff ``` Turns off all connected monitors. .EXAMPLE ```powershell poweroff ``` Turns off all connected monitors using the alias. ")] [Cmdlet(VerbsCommon.Set, "MonitorPowerOff")] [Alias("poweroff")] public class SetMonitorPowerOffCommand : PSGenXdevCmdlet { /// <summary> /// Begin processing - initialization logic /// </summary> protected override void BeginProcessing() { WriteVerbose("Preparing to turn off monitor(s)..."); } /// <summary> /// Process record - main cmdlet logic /// </summary> protected override void ProcessRecord() { // Wait briefly to allow any pending screen operations to complete System.Threading.Thread.Sleep(2000); // Check if we should proceed with turning off the monitors if (ShouldProcess("All Monitors", "Turn Off")) { // Invoke windows power management api to trigger monitor power-off GenXdev.Helpers.WindowObj.SleepMonitor(); } } /// <summary> /// End processing - cleanup logic /// </summary> protected override void EndProcessing() { } } } |