Execute Powershell function from SSH

Welcome Forums General PowerShell Q&A Execute Powershell function from SSH

This topic contains 0 replies, has 1 voice, and was last updated by  Marco 11 months, 2 weeks ago.

  • Author
  • #90328

    Points: 0
    Rank: Member

    Hello – I´m new to this Forum and to powershell. I have a home -automatisation System working mainly in python on raspberry.py (called smarthome.py). I have a touchscreen that I´d like to remotly turn on/off from that System. The screen is connected to a mini-pc running Windows 10 home.
    I was able to install the "toggleDisplay" module and it is working perfectly when I run this from powershell on the mini-pc itself. If I run it from SSH, it is not turning the Screen off nor on, allthough it is exucuted.
    The Powershell Version is 5.1.16299.98 and I connect with OpenSSH (loaded from optional Features) from Putty. The Executionplicy is unrestricted and as informed before there is no error message and the function is called but not turning of the Display (when called it returns a "1" in the console).

    Here you find the code of the module:

    Add-Type -Namespace Win32API -Name Message -MemberDefinition @'
    [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(
            int hWnd,
            UInt32 Msg,
            int wParam,
            int lParam
    $msg = @{
        HWND_Broadcast = 0xFFFF
        WM_SysCommand = 0x0112
        SC_MonitorPower = 0xF170
        PowerOn = -1
        PowerOff = 2
    Function Start-Display {
        This command will turn on the display of the computer.
        [Win32API.Message]::SendMessage($msg.HWND_Broadcast, $msg.WM_SysCommand, $msg.SC_MonitorPower, $msg.PowerOn) 
    Function Stop-Display {
        This command will turn on the display of the computer.
        [Win32API.Message]::SendMessage($msg.HWND_Broadcast, $msg.WM_SysCommand, $msg.SC_MonitorPower, $msg.PowerOff)
    New-Alias -Name sadp -Value Start-Display
    New-Alias -Name spdp -Value Stop-Display

    Thanks for your help

The topic ‘Execute Powershell function from SSH’ is closed to new replies.