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", "Webmaster@example.com") $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 […]

Read more

FIX: Attempt to load Oracle client libraries threw BadImageFormatException. This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed

Environment: You are on a Windows 7 x64 bit System Using PowerShell x64 bit Authoring a script that connects to Oracle Database via "System.Data.OracleClient" Sample Script: $connectionString = "Data Source=ORADB01.TESTLAB.LAN;User Id=root;Password=R00tUs3r;Integrated Security=no" $queryString = "select * from users where username like ‘%govardhan%’" [System.Reflection.Assembly]::LoadWithPartialName("System.Data.OracleClient") | Out-Null $connection = New-Object System.Data.OracleClient.OracleConnection($connectionString) $command = new-Object System.Data.OracleClient.OracleCommand($queryString, $connection) $connection.Open() $resources = $command.ExecuteReader() # Write out the results while ($resources.read()) {     $Process=$resources.GetDecimal(0)     $Status=$resources.GetString(1)     Write-Host $Process $Status     } $connection.Close()   Output:   PS C:>Powershell C:tempSend-Activation-Emails.ps1 Exception calling "Open" with "0" argument(s): "Attempt to load Oracle client libraries threw BadImageFormatException.  This problem will […]

Read more

PowerShell Regular Expression: Find and Replace default username with current username in an .XML configuration file

I’ve below Config file in which there are multiple instances of user profile path (C:UsersCoreluser001.Testlab.*).  This user profile path points to a default user and needs to be updated to the currently logged on user profile path (C:Users<username>.*).   PS C:> grep -i "Coreluser001" C:TempCorelConnect-Default.config <AppPrefs xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" TrayRootDirectory="C:UsersCoreluser001.TestlabDocumentsCorelCorel ContentTrays" SelectedTray="C:UsersCoreluser001.TestlabDocumentsCorelCorel ContentTraysTray">     <Folder Provider="6253a437-710e-4bda-9e51-052b9f3f41c1" LanguageIndex="0" DisplayContentIndex="0" NumResultsIndex="0" IsSearched="true" IsActivated="true" StoredTitle="Documents" Path="C:UsersCoreluser001.TestlabDocuments" />     <Folder Provider="6253a437-710e-4bda-9e51-052b9f3f41c1" LanguageIndex="0" DisplayContentIndex="0" NumResultsIndex="0" IsSearched="false" IsActivated="true" StoredTitle="My Pictures" Path="C:UsersCoreluser001.TestlabPictures" />     <Folder Provider="6253a437-710e-4bda-9e51-052b9f3f41c1" LanguageIndex="0" DisplayContentIndex="0" NumResultsIndex="0" IsSearched="true" IsActivated="true" StoredTitle="Desktop" Path="C:UsersCoreluser001.TestlabDesktop" />     <Searchable xsi:type="Folder" Provider="6253a437-710e-4bda-9e51-052b9f3f41c1" LanguageIndex="0" DisplayContentIndex="0" NumResultsIndex="0" IsSearched="true  IsActivated="true" StoredTitle="Desktop" Path="C:UsersCoreluser001.TestlabDesktop" />     <Searchable […]

Read more