Advertisement
metalx1000

Create Encoded Batch file power shell script

Jun 25th, 2014
451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#
  2. encodes all ps1 files in a folder
  3. #>
  4.  
  5. $files = Get-ChildItem -path $pwd -filter "*.ps1"
  6.  
  7. foreach($file in $files)
  8. {
  9.     write-output "Encoding $file"
  10.     $code = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes((Get-Content $file |%{$_}|out-string)))
  11.    
  12.     $bat = "powershell -encodedcommand $code"
  13.     $base = [io.path]::GetFileNameWithoutExtension("$file")
  14.     $batfile = $base + ".bat"
  15.     $bat |set-content $batfile
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement