Advertisement
Guest User

Untitled

a guest
Jul 6th, 2017
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. # Register the HNetCfg library (once)
  2. regsvr32 /s hnetcfg.dll
  3.  
  4. # Create a NetSharingManager object
  5. $m = New-Object -ComObject HNetCfg.HNetShare
  6.  
  7. # Find connection
  8. $conn_1 = $m.EnumEveryConnection |? { $m.NetConnectionProps.Invoke($_).Name -eq "Ethernet" }
  9. $conn_2 = $m.EnumEveryConnection |? { $m.NetConnectionProps.Invoke($_).Name -eq "VirtualBox Host-Only Network" }
  10.  
  11. # Get sharing configuration
  12. $config_1 = $m.INetSharingConfigurationForINetConnection.Invoke($conn_1)
  13. $config_2 = $m.INetSharingConfigurationForINetConnection.Invoke($conn_2)
  14.  
  15. # Disable sharing
  16. Write-Host "Disable Sharing"
  17. $config_1.DisableSharing()
  18. $config_2.DisableSharing()
  19.  
  20. # Enable sharing
  21. Write-Host "Enable Sharing"
  22. $config_1.EnableSharing(0)
  23. $config_2.EnableSharing(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement