PowerShell Learning: Here-String (@” “@)

PowerShell : Here-String
PowerShell : Here-String

Hi All,

Greetings.

In this article I will discuss one of the PowerShell string concept – Here-String

What is Here-String?

  • Here-String are used to declare multi line text.
  • Here-String are specifically useful for managing large blocks of text like HTML, XML, JSON or SQL queries
  • Here-String is enclosed within @" and "@ delimiters, with the text in between.

Syntax:

  • A here-string is enclosed by an at sign (@) and a single or double quotation mark (or ")
  • A here-string ends with a newline followed instantly by "@ or '@ on its own line

Example:

PS C:\> $test = @"
>> {
>> <!doctype html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"></html>
>> }
>> "@

  • In the above example we have declared the variable $test, which includes the HTML text

PS C:\> $test
{
<!doctype html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"></html>
}
PS C:\>

Screenshot of a PowerShell terminal displaying an error message regarding a here-string header in a script, with highlighted error text.
image 1: PowerShell – Here-String example

Use cases of Here-String

  • Here-String are specifically useful for managing large blocks of text like HTML, XML, JSON or SQL queries
  • Here-String are useful to store code snippets of languages (like C# or Python) within a PowerShell script
  • Here-String are useful for API calls
  • Here-String are useful while using special characters, like single and double quotes. These characters can be used without escaping
  • We can use Here-String to store and manipulate the file content
  • Here-String can also be used to create CSV file

Thanks for reading ! Stay tuned for more PowerShell concepts !

HAPPY LEARNING AHEAD 🙂 LIFE IS BEAUTIFUL 🙂

Prasham Sabadra

LIFE IS VERY BEAUTIFUL. ENJOY THE WHOLE JOURNEY :) Founder of Microsoft 365 Junction, Speaker, Author, Learner, Developer, Passionate Techie. Certified Professional Workshop Facilitator / Public Speaker. Believe in knowledge sharing. Around 20+ years of total IT experience and 17+ years of experience in SharePoint and Microsoft 365 services Please feel free me to contact for any SharePoint / Microsoft 365 queries. I am also very much interested in behavioral (life changing) sessions like motivational speeches, Success, Goal Setting, About Life, How to live Life etc. My book - Microsoft 365 Power Shell hand book for Administrators and Beginners and 100 Power Shell Interview Questions - https://www.amazon.in/Microsoft-Administrators-Beginners-Interview-Questions/dp/9394901639/ref=tmm_pap_swatch_0?_encoding=UTF8&qid=1679029081&sr=8-11

You may also like...

1 Response

  1. February 13, 2026

    […] We have detailed article on here-string – PowerShell Learning: Here-String (@” “@) […]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Microsoft 365

Subscribe now to keep reading and get access to the full archive.

Continue reading