in

Getting error while executing powershell script from powershell


I am getting the below error while executing the below code
Code :

$localScriptPath= "C:AshishGpowershellscript12.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`" $argumentList"
Write-Host "scriptPath" used is $output

Code explanation:

  1. Assign the path of the script into a variable.
  2. assign the encoded string to a variable
  3. decoding the string and copy into a file.
  4. 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:AshishGpowershellscript12.ps1:1 char:1
+ Write-Host 'script is executed successfully'
+ ~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Write-Host:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Please see the below points.

  1. I am getting the error while executing the powerscript (C:AshishGpowershellscript12.ps1).
  2. The string is in an encoded format and I can decode it and I see, the decoded string is also fine.
  3. 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?



Source: https://stackoverflow.com/questions/70539189/getting-error-while-executing-powershell-script-from-powershell

Five day forecast for loop not returning data

Friendhosting LTD: ⚡New Year FLASH SALE⚡Discount up to 50% for VPS orders. VPS from $1.70/month