用于启用ICS服务的脚本


1

我尝试构建脚本来选择专用网络并启用部分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服务并启用其中的一部分 有人有任何线索吗?

enter image description here


您使用的是什么(古代)windows / powershell版本? - > $PSVersionTable
LotPings

它的Windows Server 2008
user9897732
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.