Poniższy kod wyłącza PSRemoting, serwis i usuwa listenerów:
function Restart-PSRemoting
{
param(
[Switch]$restartService,
[Switch]$removeListeners,
[Switch]$WhatIf,
[Switch]$enable,
[int[]]$listenerPorts=(5985,5986)
)
Disable-PSRemoting -Force -WhatIf:$WhatIf
if($restartService)
{
Set-Service winrm -StartupType Manual -WhatIf:$WhatIf
Stop-Service winrm -WhatIf:$WhatIf
}
if($removeListeners)
{
gci WSMan:\localhost\Listener -Recurse |
%{ $_.PSPath} |
?{
$port = (gci "$_\port").Value
$listenerPorts -contains $port
}|
Remove-Item -WhatIf:$WhatIf
}
if($enable)
{
Enable-PSRemoting -Force -WhatIf:$WhatIf
}
}
Aby sprawić co zrobi polecenie wystarczy wywołać polecenie z parametrem WhatIF
Restart-PSRemoting -WhatIf -removeListeners -enable -restartService
Brak komentarzy:
Prześlij komentarz