Home » PowerShell » PowerShell Tab Character

PowerShell Tab Character

Use `t to insert a tab character in the PowerShell string. The PowerShell tab character is represented by a backtick (`) character followed by the character "t".

PowerShell Tab Character in String
PowerShell Tab Character in String

In PowerShell, all special characters start with a backtick (`). Horizontal tab special character (`t) inserts eight spaces by default and continues writing from that point onwards.

In this article, we will discuss how to insert a PowerShell tab character in a string.

PowerShell Insert Tab Character in String

In PowerShell use `t to add a tab in string. It inserts a tab in a string.

$str = "Shell`tGeek"
Write-Host "Welcome to Shell`tGeek"     

In the above PowerShell script, the $str variable stores the string. In the double quotes, the `t tab character inserts a tab in the string.

The output of the above PowerShell script prints the string having a tab space between the word.

The string “Shell`tGeek” contains a tab character `t to separate two words Shell and Geek by a tab.

PS C:\> $str = "Shell`tGeek"                                                                                            
PS C:\> $str                                                                                                            
Shell        Geek
PS C:\>                                                                                                                 
                                                                                                              
PS C:\> Write-Host "Welcome to Shell`tGeek"                                                                             Welcome to Shell        Geek

Use ASCII Code for the PowerShell Tab Character

The ASCII code for the tab character is 09. Using the ASCII code for the tab character, it can insert a tab into a PowerShell string.

$tab = [char]9   
Write-Host "Sr.No $tab Name $tab Salary"

In the above PowerShell script, the $tab stores ASCII code for the tab character. Write-Host cmdlet in PowerShell prints the string separated by a tab character.

The output of the above PowerShell script is:

PS C:\> $tab = [char]9                                                                                                  

PS C:\> Write-Host "Sr.No $tab Name $tab Salary"                                                                        Sr.No        Name        Salary

PS C:\>    

Conclusion

I hope the above article on how to use the PowerShell tab character in a string is useful to you.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.