Public/Wifi/Get-WifiConnectionProfile.ps1

Function Get-WifiConnectionProfile {
  <#
.SYNOPSIS
    Retrieves all Wi-Fi connection profiles on the system.
 
.DESCRIPTION
    This function retrieves the Wi-Fi connection profiles from the system using
    the `GetConnectionProfiles()` method. It filters the profiles to only include
    Wi-Fi (WLAN) profiles. If no Wi-Fi profiles are found, it provides a verbose message.
 
.EXAMPLE
    Get-WifiConnectionProfile
    Retrieves all Wi-Fi connection profiles on the system.
 
.NOTES
    This function is useful for checking the existing Wi-Fi profiles on the system.
#>

  [OutputType([Windows.Networking.Connectivity.ConnectionProfile])]
  Param()
  Process {
    try {
      $Profiles = [Windows.Networking.Connectivity.NetworkInformation]::GetConnectionProfiles()
      $WifiProfiles = $Profiles | Where-Object { $_.IsWlanConnectionProfile }
      if ($null -eq $WifiProfiles) {
        Write-Verbose "No WiFi connection profiles found on this system."
      }
      return $WifiProfiles
    } catch {
      Write-Error "Failed to retrieve connection profiles: $($_.Exception.Message)"
    }
  }
}