File: //var/opt/nydus/ops/customer_local_ops/operating_system/powershell/enable_winexe.ps1
function Ensure-NetFirewallRule {
param($displayName, $direction, $action, $protocol, $localPort)
if(Get-NetFirewallRule -DisplayName $displayName -ea SilentlyContinue){
Remove-NetFirewallRule -DisplayName $displayName
}
New-NetFirewallRule -DisplayName $displayName -Direction $direction -Action $action -Protocol $protocol -LocalPort $localPort
}
Enable-PSRemoting -Force
"Configuring firewall"
Ensure-NetFirewallRule -DisplayName "winexe" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 139
netsh advfirewall firewall set rule name=winexe new localport=139,445
# Remove the blocks set up in the image by OH. NOTE: The spaces in the rule names are required. That's how
# the rules were created.
Remove-NetFirewallRule -DisplayName "Block TCP 139 " -ea SilentlyContinue
Remove-NetFirewallRule -DisplayName "Block TCP 445 " -ea SilentlyContinue
"Auto-restart Lanman Server on failure"
sc.exe failure LanManServer reset= 3600 actions= restart/5000/restart/10000/restart/5000
"Fix Lanman Server dependencies"
# SamSS=Security Accounts Manager; Srv2=SMB2 driver
sc.exe config lanmanserver depend= SamSS/Srv2
sc.exe start lanmanserver