Powershell - check if WLAN connected

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
 function Get-IniFile  
 {   
   param(   
     [parameter(Mandatory = $true)] [string] $filePath   
   )   
   $anonymous = "NoSection"  
   $ini = @{}   
   switch -regex -file $filePath   
   {   
     "^\[(.+)\]$" # Section   
     {   
       $section = $matches[1]   
       $ini[$section] = @{}   
       $CommentCount = 0   
     }   
     "^(;.*)$" # Comment   
     {   
       if (!($section))   
       {   
         $section = $anonymous   
         $ini[$section] = @{}   
       }   
       $value = $matches[1]   
       $CommentCount = $CommentCount + 1   
       $name = "Comment" + $CommentCount   
       $ini[$section][$name] = $value   
     }    
     "(.+?)\s*=\s*(.*)" # Key   
     {   
       if (!($section))   
       {   
         $section = $anonymous   
         $ini[$section] = @{}   
       }   
       $name,$value = $matches[1..2]   
       $ini[$section][$name] = $value   
     }   
   }   
   return $ini   
 }   
 $iniFile = Get-IniFile "c:\info\additional_info.ini"  
 $PreferredSSID = $iniFile.NoSection.SerialNumber  
 Function AutoConnect ($PreferredSSID){  
   #WIFI auto-connect  
   if($PreferredSSID -ne $null){  
     if(Get-NetAdapter | where {($_.Name -like "*wi-fi*" -or $_.Name -like "*wifi*") -and ($_.Status -eq "Disconnected")}){  
       netsh wlan connect name=$PreferredSSID  
       Start-Sleep -Seconds 2  
       netsh wlan set profileparameter name=$PreferredSSID connectionmode=auto  
     }  
   }  
 }  
 while ( Get-NetAdapter | where {($_.Name -like "*wi-fi*" -or $_.Name -like "*wifi*") -and ($_.Status -eq "Disconnected")}){  
   AutoConnect $PreferredSSID  
   Start-Sleep -Seconds 2  
 }  

additional_ino.ini file:

1
2
SerialNumber = 35356345601
CalibrationDate = 22 Oct 2010

Keine Kommentare:

Kommentar veröffentlichen

Datei in einer windows.wim image ändern

 Um Dateien in einer Datei.wim zu ändern, und zwar nicht im 1. Index sondern 2. öffnet man Powershell (ich habs jetzt im admin Modus gestart...