我尝试构建脚本来选择专用网络并启用部分ICS服务。我用这些代码选择专用网络:
{
# Constants
$public = 0
$private = 1
Write-Host "Creating netshare object..."
$netshare = New-Object -ComObject HNetCfg.HNetShare
Write-Host "Getting public adapter..."
$publicadapter = $netshare.EnumEveryConnection | Where-Object {
$netshare.NetConnectionProps($_).Name -eq "Local Area Connection"
}#foreach
Write-Host "Getting private adapter..."
$privateadapter = $netshare.EnumEveryConnection | Where-Object {
$netshare.NetConnectionProps($_).Name -eq "Peer2Peer"
}#foreach
Write-Host "Disabling sharing for adapters...."
$netshare.INetSharingConfigurationForINetConnection($privateadapter).DisableSharing()
$netshare.INetSharingConfigurationForINetConnection($publicadapter).DisableSharing()
Start-Sleep -s 3
Write-Host "Enabling sharing for private adapter...."
$netshare.INetSharingConfigurationForINetConnection($privateadapter).EnableSharing($private)
Write-Host "Enabling sharing for public adapter...."
$netshare.INetSharingConfigurationForINetConnection($publicadapter).EnableSharing($public)
# Clean up
Remove-Variable netshare
}
我想获得所有ICS服务并启用其中的一部分 有人有任何线索吗?
它的Windows Server 2008
—
user9897732
$PSVersionTable