I am getting the below error while executing the below code Code :
$localScriptPath= "C:\AshishG\powershell\script12.ps1"
$ëncodedResonse = "77u/V3JpdGUtSG9zdCAnc2NyaXB0IGlzIGV4ZWN1dGVkIHN1Y2Nlc3NmdWxseScNCg0KcmV0dXJuICdUaGlzIGlzIHNjcmlwdCBvdXRwdXQn"
Write-Output "ëncodedResonse used is $ëncodedResonse"
[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($ëncodedResonse)) | Out-File $localScriptPath -Force
$Content2 = get-content $localScriptPath
Write-Host "DECODED: " $Content2
$output =Invoke-Expression "& `"$localScriptPath`" "
Write-Host "scriptPath" used is $output
Code explanation:
- Assign the path of the script into a variable.
- assign the encoded string to a variable
- decoding the string and copy into a file.
- Executing the PowerShell script and getting the error.
Error:
Write-Host : The term 'Write-Host' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a
path was included, verify that the path is correct and try again.
At C:\AshishG\powershell\script12.ps1:1 char:1
+ Write-Host 'script is executed successfully'
+ ~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Write-Host:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Please see the below points.
- I am getting the error while executing the powerscript (C:\AshishG\powershell\script12.ps1).
- The string is in an encoded format and I can decode it and I see, the decoded string is also fine.
- I observe, The script12.ps1 is generated in UTF-16 LE BOM format. is it creating the issue?
I have written complete code because I am not sure what is the issue?