FIX: PowerShell V1.0 : Unrecognized token in source text.

When you try to print or access the Hashes in PowerShell v1.0 using @ operator, you’ll receive the error message detailed in this article below.  In PowerShell v1.0, you instead need to use $ operator to refer to an hash variable.

Code:

$email = @{}
$email.Add("From", "TestSender")
$email.Add("To", "[email protected]")
$email.Add("Subject", "Test mail from PowerShell 1.0")
$email.Add("Body", “Hi There, Reply me back”)

@email

 

Error:

PS C:Test> powershell C:Testtest-hases.ps1
Unrecognized token in source text.
At C:packagingtest-hases.ps1:9 char:13
+     write-host @ <<<< email
PS C:Test>

 

Fix:

In PowerShell v1.0, a hash cannot be print using the @<hashname> operator. Instead, you can print the output by specifying the Hash as $<hashname>

 

Verification:

$email = @{}
$email.Add("From", "TestSender")
$email.Add("To", "[email protected]")
$email.Add("Subject", "Test mail from PowerShell 1.0")
$email.Add("Body", “Hi There, Reply me back”)

$email

PS C:> powershell C:Testtest-hases.ps1

Name                           Value
—-                           —–
Body                           Hi There, Reply me back
Subject                        Test mail from PowerShell 1.0
To                             [email protected]
From                           TestSender

PS C:>

Leave a Reply

Your email address will not be published. Required fields are marked *