I have below powershell commands,
$tmp = Get-Content 'C:\Users\username\Documents\emp_details.txt'
$tmp[0..75], ':tech emp details', $tmp[76.. ($tmp.Count -1)] |
Set-Content 'C:\Users\username\Documents\emp_details.txt'
which I want to encode and this entire commands as string and store it to variable and then will decode and execute it whenever I needed. But when I tried to decode using below which internally executes the Get-Content command as well.
$Bytes = [System.Text.Encoding]::Unicode.GetBytes("$tmp = Get-Content 'C:\Users\username\Documents\emp_details.txt'
$tmp[0..75], ':tech emp details', $tmp[76.. ($tmp.Count -1)] |
Set-Content 'C:\Users\username\Documents\emp_details.txt'")
$EncodedText =[Convert]::ToBase64String($Bytes)
$EncodedText
Any idea please to encode those commands as strings without executing those commands internally.