Powershell Invoke and multiple lines

Hi,

I am trying to run a 15 line code using Invoke Powershell. I can copy and paste this 15 line of code and not execute it because it misinterprets the code and gives me an error message. What possibilities are there to execute a programming code via invoke without reading it in and executing it via a read file? The code works fine via read file.

Hi @Crusha ,

Could you let us know what is that you want to perform ? You did mention the code works fine by First Reading the file and using it Invoke Powershell Activity.

Let us know what exactly is that your looking for.

I have a larger script. But I would like to work with variables in some things, e.g.:

$date = get-date -Format "yyyy_MM_dd-hhmmss"
$Log = "ErrLog_$($date).txt"
$Error.Clear()
$AktDate = get-date -Format "dd.MM.yyyy hh:mm:ss"

"Start: $($AktDate)" | Out-File $Log

$setPW = 0
$debug = 0

if($debug -eq 1){
    $PWDatei = "psK_cm.txt"
} else {
    $PWDatei = "psK.txt"
}

Hello Crusha,
This video might help you: https://www.youtube.com/watch?v=wKZu86GzHOo
Just to give you an idea, this is how I implemented a script that sets the local settings in my VM with the following Invoke powershell activity:

To be honest I would not leave the powershell command text very open ended. Imagine the scenario where the powershell command is in a txt file in a shared drive and local robot users have quite extensive administrator privilages. In that case if a human user with or without bad intentions, edits that txt file and all your VM’s can be affected by that. In my case I designed in a way that the powershell is hardcoded inside the activity and a change can be implemented by publishing to the orchestrator. This command is not something we would change frequently anyway.
Best