SHARE
TWEET

Untitled

a guest Jul 21st, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Add-Type -AssemblyName System.Runtime.WindowsRuntime
  2. $asTaskGeneric = ([System.WindowsRuntimeSystemExtensions].GetMethods() | ? { $_.Name -eq 'AsTask' -and $_.GetParameters().Count -eq 1 -and $_.GetParameters()[0].ParameterType.Name -eq 'IAsyncOperation`1' })[0]
  3. Function Await($WinRtTask, $ResultType) {
  4.     $asTask = $asTaskGeneric.MakeGenericMethod($ResultType)
  5.     $netTask = $asTask.Invoke($null, @($WinRtTask))
  6.     $netTask.Wait(-1) | Out-Null
  7.     $netTask.Result
  8. }
  9. Function AwaitAction($WinRtAction) {
  10.     $asTask = ([System.WindowsRuntimeSystemExtensions].GetMethods() | ? { $_.Name -eq 'AsTask' -and $_.GetParameters().Count -eq 1 -and !$_.IsGenericMethod })[0]
  11.     $netTask = $asTask.Invoke($null, @($WinRtAction))
  12.     $netTask.Wait(-1) | Out-Null
  13. }
  14.  
  15. $connectionProfile = [Windows.Networking.Connectivity.NetworkInformation,Windows.Networking.Connectivity,ContentType=WindowsRuntime]::GetInternetConnectionProfile()
  16. $tetheringManager = [Windows.Networking.NetworkOperators.NetworkOperatorTetheringManager,Windows.Networking.NetworkOperators,ContentType=WindowsRuntime]::CreateFromConnectionProfile($connectionProfile)
  17.  
  18. $tetheringConfiguration = [Windows.Networking.NetworkOperators.NetworkOperatorTetheringAccessPointConfiguration,Windows.Networking.NetworkOperators,ContentType=WindowsRuntime]::new()
  19. $tetheringConfiguration.Ssid = "BG2"
  20. $tetheringConfiguration.Passphrase = "NewP@ssw0rd2"
  21.  
  22. AwaitAction ($tetheringManager.ConfigureAccessPointAsync($tetheringConfiguration))
  23. $tetheringManager.GetCurrentAccessPointConfiguration()
  24.  
  25. # Check whether Mobile Hotspot is enabled
  26. if ($tetheringManager.TetheringOperationalState -eq "Off")
  27. {
  28.     Await ($tetheringManager.StartTetheringAsync()) ([Windows.Networking.NetworkOperators.NetworkOperatorTetheringOperationResult])
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top