# Switch

Switches toggle the state of a single setting on or off.

Switches are the preferred way to adjust settings on mobile. The option that the switch controls, as well as the state it’s in, should be made clear from the corresponding inline label.

## Switch

Create a basic switch.

![](/files/OeO7EJ6YnSyMMMoogxR5)

```powershell
New-UDSwitch -Checked $true 
New-UDSwitch -Checked $true -Disabled
```

## OnChange Event

Respond to when a switch value is changed. The `$EventData` variable will include whether or not the switch was checked or unchecked.

```powershell
New-UDSwitch -OnChange { Show-UDToast -Message $EventData }
```

## Get-UDElement Support

You can retrieve the value of the switch within another component by using `Get-UDElement`. Use the Checked property to determine whether the switch is checked out not.

```powershell
New-UDSwitch -Id 'switch' 
New-UDButton -Text 'Click' -OnClick {
    Show-UDToast -Message (Get-UDElement -Id 'switch').checked
}
```

## API

* [New-UDSwitch](https://github.com/ironmansoftware/universal-docs/blob/v5/cmdlets/New-UDSwitch.txt)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.powershelluniversal.com/apps/components/inputs/switch.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
