admin 管理员组文章数量: 1086019
I want to modify certain network sharing options using a PowerShell script. Specifically, I need to automate the following actions, accessible via:
Windows + R -> control /name Microsoft.NetworkAndSharingCenter /page Advanced
In the "All Networks" section → "Public folder sharing", select:
"Turn on sharing so anyone with network access can read and write files in the Public folders"
In the "File sharing connections" section, select:
"Use 128-bit encryption to help protect file sharing connections (recommended)"
In the "Password protected sharing" section, select:
"Turn off password protected sharing"
I have developed the following PowerShell script. It runs without any errors, but the desired options are not selected. The script has no effect on the selection of the options. Do you have any idea what might be causing the issue?
# 16. Modify sharing settings
if ($config.Configurations.PartageAvance) {
Write-Log "16. Configuring advanced sharing settings..."
try {
# Enable file and printer sharing for all network profiles
$networkProfiles = @("Private", "Public", "Domain")
# Use Get-NetFirewallRule to find sharing rules
$fileAndPrinterSharingRules = Get-NetFirewallRule | Where-Object {
$_.DisplayGroup -like "*File and Printer Sharing*"
}
foreach ($rule in $fileAndPrinterSharingRules) {
Set-NetFirewallRule -Name $rule.Name -Enabled True -Profile $networkProfiles
}
# Alternative method using netsh
netsh advfirewall firewall set rule group="File and Printer Sharing" new enable=Yes | Out-Null
# Disable password-protected sharing
$regPath = "HKLM:\SYSTEM\CurrentControlSet\Control\Lsa"
Set-ItemProperty -Path $regPath -Name "LmCompatibilityLevel" -Value 1 -Type DWord
$regPath = "HKLM:\SYSTEM\CurrentControlSet\Services\LanmanWorkstation\Parameters"
Set-ItemProperty -Path $regPath -Name "RequireSecuritySignature" -Value 0 -Type DWord
Set-ItemProperty -Path $regPath -Name "EnableSecuritySignature" -Value 0 -Type DWord
$regPath = "HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters"
Set-ItemProperty -Path $regPath -Name "RequireSecuritySignature" -Value 0 -Type DWord
Set-ItemProperty -Path $regPath -Name "EnableSecuritySignature" -Value 0 -Type DWord
Set-ItemProperty -Path $regPath -Name "RestrictNullSessAccess" -Value 0 -Type DWord
Write-Log "Sharing settings configured" -ForegroundColor Green
}
catch {
Write-Log "Error configuring sharing settings: $_" -ForegroundColor Red
}
}
else {
Write-Log "Sharing settings configuration disabled" -ForegroundColor Yellow
}
本文标签: windowsConfigure Network Sharing Options via PowerShellStack Overflow
版权声明:本文标题:windows - Configure Network Sharing Options via PowerShell - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1744069991a2528309.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论