There is no precise powershell command to toggle airplane mode, the only thing we can do is toggle the network adapter, which is not what we wanted.
Instead we can achieve this by pywinauto or pyautogui. These are python modules to automate desktop apps.
below is the pywinauto script to toggle the airplane mode
I tried with pywinauto module and able to toggle it.
import time import subprocess from pywinauto import Application
subprocess.Popen(['start', 'ms-settings:'], shell=True) time.sleep(3)
app = Application(backend="uia").connect(title_re=".Settings.") # Use regex to match window title settings_window = app.window(title_re=".Settings.")
network_internet_item = settings_window.child_window(title="Network & internet", control_type="ListItem") network_internet_item.click_input() time.sleep(1)
airplane_mode_item = settings_window.child_window(title="Airplane mode", control_type="ListItem") airplane_mode_item.click_input() time.sleep(1)
airplane_mode_toggle = settings_window.child_window(auto_id="SystemSettings_Radio_IsAirplaneModeEnabled_SettingsApp_ToggleSwitch", control_type="Button") airplane_mode_toggle.click_input()
The typical method of navigating to airplane mode toggle button and clicking enter is not working. So, could not think of other solution apart from this