mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
using shell='powershell'
This commit is contained in:
parent
1caa086a2f
commit
57267d4716
@ -9,7 +9,6 @@ import re
|
||||
# Import salt libs
|
||||
import salt.utils
|
||||
|
||||
POWERSHELL = 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe'
|
||||
|
||||
|
||||
def __virtual__():
|
||||
@ -31,6 +30,13 @@ def _parse_return_code_powershell(string):
|
||||
else:
|
||||
return int(regex.group(1))
|
||||
|
||||
def _psrdp(cmd)
|
||||
'''
|
||||
Create a Win32_TerminalServiceSetting WMI Object as $RDP and execute the command cmd
|
||||
returns the STDOUT of the command
|
||||
'''
|
||||
rdp = '$RDP = Get-WmiObject -Class Win32_TerminalServiceSetting -Namespace root\\CIMV2\\TerminalServices -Computer . -Authentication 6 -ErrorAction Stop'
|
||||
return __salt__['cmd.run']('{0} ; {1}'.format(rdp, cmd), shell='powershell')
|
||||
|
||||
def enable():
|
||||
'''
|
||||
@ -43,9 +49,7 @@ def enable():
|
||||
salt '*' rdp.enable
|
||||
'''
|
||||
|
||||
cmd = '-InputFormat None -Command "& { $RDP = Get-WmiObject -Class Win32_TerminalServiceSetting -Namespace root\\CIMV2\\TerminalServices -Computer . -Authentication 6 -ErrorAction Stop ; $RDP.SetAllowTsConnections(1,1) }"'
|
||||
cmd = '{0} {1}'.format(POWERSHELL, cmd)
|
||||
return _parse_return_code_powershell(__salt__['cmd.run'](cmd)) == 0
|
||||
return _parse_return_code_powershell(_psrdp('$RDP.SetAllowTsConnections(1,1)')) == 0
|
||||
|
||||
|
||||
def disable():
|
||||
@ -59,9 +63,7 @@ def disable():
|
||||
salt '*' rdp.disable
|
||||
'''
|
||||
|
||||
cmd = '-InputFormat None -Command "& { $RDP = Get-WmiObject -Class Win32_TerminalServiceSetting -Namespace root\\CIMV2\\TerminalServices -Computer . -Authentication 6 -ErrorAction Stop ; $RDP.SetAllowTsConnections(0,1) }"'
|
||||
cmd = '{0} {1}'.format(POWERSHELL, cmd)
|
||||
return _parse_return_code_powershell(__salt__['cmd.run'](cmd)) == 0
|
||||
return _parse_return_code_powershell(_psrdp('$RDP.SetAllowTsConnections(0,1)')) == 0
|
||||
|
||||
|
||||
def status():
|
||||
@ -75,7 +77,5 @@ def status():
|
||||
salt '*' rdp.status
|
||||
'''
|
||||
|
||||
cmd = '-InputFormat None -Command "& { $RDP = Get-WmiObject -Class Win32_TerminalServiceSetting -Namespace root\\CIMV2\\TerminalServices -Computer . -Authentication 6 -ErrorAction Stop ; echo $RDP.AllowTSConnections }"'
|
||||
cmd = '{0} {1}'.format(POWERSHELL, cmd)
|
||||
out = int(__salt__['cmd.run'](cmd).strip())
|
||||
out = int(_psrdp('echo $RDP.AllowTSConnections').strip())
|
||||
return out != 0
|
||||
|
@ -20,7 +20,7 @@ def _srvmgr(func):
|
||||
'''
|
||||
Execute a function from the ServerManager PS module and return the STDOUT
|
||||
'''
|
||||
return __salt__['cmd.run']('C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell -InputFormat None -Command "& {{ Import-Module ServerManager ; {0} }}"'.format(func))
|
||||
return __salt__['cmd.run']('Import-Module ServerManager ; {0}'.format(func), shell='powershell')
|
||||
|
||||
|
||||
def _parse_powershell_list(lst):
|
||||
@ -96,7 +96,7 @@ def install(feature, recurse=False):
|
||||
sub = ''
|
||||
if recurse:
|
||||
sub = '-IncludeAllSubFeature'
|
||||
out = _srvmgr('Add-WindowsFeature -Name {0} {1} -erroraction silentlycontinue | format-list'.format(feature, sub))
|
||||
out = _srvmgr('"Add-WindowsFeature -Name {0} {1} -erroraction silentlycontinue | format-list"'.format(feature, sub))
|
||||
return _parse_powershell_list(out)
|
||||
|
||||
|
||||
@ -117,5 +117,5 @@ def remove(feature):
|
||||
|
||||
salt -t 600 '*' win_servermanager.remove Telnet-Client
|
||||
'''
|
||||
out = _srvmgr('Remove-WindowsFeature -Name {0} -erroraction silentlycontinue | format-list'.format(feature))
|
||||
out = _srvmgr('"Remove-WindowsFeature -Name {0} -erroraction silentlycontinue | format-list"'.format(feature))
|
||||
return _parse_powershell_list(out)
|
||||
|
Loading…
Reference in New Issue
Block a user