Saya mencoba membuat skrip untuk memilih jaringan pribadi dan mengaktifkan bagian dari layanan ICS. Saya memilih jaringan pribadi dengan kode ini:
{
# 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
}
Saya ingin mendapatkan semua layanan ICS dan memungkinkan sebagian dari mereka memiliki petunjuk?
powershell
python
cmd.exe
c#
pengguna9897732
sumber
sumber
$PSVersionTable