powershell - How to change logon enable/disable remotely -
when change mode of logons on terminal servers disable. forget reenable before close session. can not reconnect change if.
you can use wmi win32_terminalservicesetting check , change status of tslogons
get-wmiobject win32_terminalservicesetting -n "root/cimv2/terminalservices" -computername $_ -authentication packetprivacy
i write 2 function enable , disable on many computers simultanusly
function logondisable { param ( [parameter(mandatory=$true,position=0)] [alias("cn")] [string[]]$computername ) try { $computername | select-object -unique | %{ $ts_connector = get-wmiobject win32_terminalservicesetting -n "root/cimv2/terminalservices" -computername $_ -authentication packetprivacy $ts_connector.logons=1 $ts_connector.put() $ts_connector.get() if ($ts_connector.logons -eq 1) { "ok" } else { "error" } } }#try catch { write-warning -message "$($error[0].exception)" } } function logonenable { param ( [parameter(mandatory=$true,position=0)] [alias("cn")] [string[]]$computername ) try { $computername | select-object -unique | %{ $ts_connector = get-wmiobject win32_terminalservicesetting -n "root/cimv2/terminalservices" -computername $_ -authentication packetprivacy $ts_connector.logons=0 $ts_connector.put() $ts_connector.get() if ($ts_connector.logons -eq 0) { "ok" } else { "error" } } }#try catch { write-warning -message "$($error[0].exception)" } }
Comments
Post a Comment