启用 ICS 服务的脚本

启用 ICS 服务的脚本

我尝试构建脚本来选择私有网络并启用部分 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 服务并启用其中的一部分,有人知道吗?

在此处输入图片描述

相关内容