Question: I want to make a selection list, to select an installed printer. But the default printer has to be on top of that list. How can i switch lets say index 5 of an array with index 0?

I know i can do this a lot of ways, but only want to know if it is possible to change index numbers of an array.

This is already working code:

```bsh
$Printers = Get-Printer
$DefaultPrinter = Get-WmiObject -Query " SELECT * FROM Win32_Printer WHERE Default=$true" | Select -Expand Name
$PrinterSelection = $Printers.Name

```

`$PrinterSelection` output: (Brother printer is default)

> 
> Verzenden naar OneNote 16   
> 
>  OneNote   
> 
>  Microsoft XPS Document Writer   
> 
>  Microsoft Print to PDF   
> 
>  Fax   
> 
>  Brother DCP-J4120DW Printer   
> 
>  Adobe PDF
> 
> 
> 

```bsh
$FirstPrinter = $PrinterSelection[0]
$DefaultPrinterNumber = [array]::indexof($PrinterSelection,$DefaultPrinter)
$PrinterSelection[0] = $DefaultPrinter
$PrinterSelection[$DefaultPrinterNumber] = $FirstPrinter

```

`$PrinterSelection` output:

> 
> Brother DCP-J4120DW Printer   
> 
>  OneNote   
> 
>  Microsoft XPS Document Writer   
> 
>  Microsoft Print to PDF   
> 
>  Fax   
> 
>  Verzenden naar OneNote 16   
> 
>  Adobe PDF
> 
> 
> 

Problem solved, but is there a cleaner way?  

In normal steps:  

Cut `$PrinterSelection[$DefaultPrinterNumber]` Insert `$PrinterSelection[0]` (not overwrite)

Answer: 
You can use the `Remove()` and `Insert()` methods of a generic list to do this. Generic lists are mutable. In this case, I'm typing the list items as strings.

```
$printerselection = $printers.name -as 'System.Collections.Generic.List[String]'
$printerselection.Remove($Defaultprinter)
$printerselection.Insert(0,$Defaultprinter)

```

The `-as` operator will change the type of your `$printers.name` output from array to **System.Collections.Generic.List`1[System.String]** granting mutability and access to the methods.
You can swap positions 0 and 5 like this:

```
$a[0],$a[5] = $a[5],$a[0]

```