unable to run PowerShell script

Copper Contributor

I am on windows 7 professional and created a powershell script that I cannot run. my security setting is set to  unrestricted. I have run it 3 ways and nothing happens.

 

First I right click the script and choose Run with PowerShell, cmd window pops up stays up for few seconds and closes by itself, nothing happens.

 

Second I open the cmd and use .\encrypt_daily_file.ps1 command and run it from the directory where the script is saved, the script file is opens in notepad, that's it.

 

Third I paste powershell -executionpolicy bypass -File .\encrypt_file2.ps1 in cmd window and the commad is written to the screen but nothing happens

 

Here is my script

 

$gpgr = 'gpg --yes --recipient junk'

<#$filename = '\\web02\SFTP\users\FROM\Encounter_NPI_'#>
$filename = 'm:\depression sub query'
$date = (Get-Date).ToString('yyyyMMdd')
$encrypt = '--encrypt "' + $filename + '.txt"'
<#$output = '--output "'+ 'c:\documents\Encounter_NPI_' + $date + '.txt.gpg"'#>
$output = '--output "'+ 'm:\depression sub query' + $date + '.txt.gpg"'
$gpgr + ' ' + $output + ' ' + $encrypt

2 Replies

@iworkonlineHello. For some reason, you didn't try the most obvious thing. Open PowerShell and issue the following command:

.\encrypt_daily_file.ps1

If PowerShell triggered an execution policy error, try this:

Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process

And then run the script again.

As for why your first action is not working, it is a Windows 7 bug. Microsoft implemented erroneous file association data in Registry. To fix that, you have to open notepad, add the following contents and save the resulting file as "1.reg" with Unicode encoding. Then run it and have it merge with Windows Registry.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Microsoft.PowerShellScript.1]
"EditFlags"=dword:00020000
"FriendlyTypeName"=hex(2):40,00,22,00,25,00,73,00,79,00,73,00,74,00,65,00,6d,\
  00,72,00,6f,00,6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,\
  33,00,32,00,5c,00,77,00,69,00,6e,00,64,00,6f,00,77,00,73,00,70,00,6f,00,77,\
  00,65,00,72,00,73,00,68,00,65,00,6c,00,6c,00,5c,00,76,00,31,00,2e,00,30,00,\
  5c,00,70,00,6f,00,77,00,65,00,72,00,73,00,68,00,65,00,6c,00,6c,00,2e,00,65,\
  00,78,00,65,00,22,00,2c,00,2d,00,31,00,30,00,33,00,00,00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Microsoft.PowerShellScript.1\DefaultIcon]
@="\"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell_ise.exe\",1"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Microsoft.PowerShellScript.1\Shell]
@="Open"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Microsoft.PowerShellScript.1\Shell\0]
"MUIVerb"=hex(2):40,00,22,00,25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,\
  6f,00,6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,\
  00,5c,00,77,00,69,00,6e,00,64,00,6f,00,77,00,73,00,70,00,6f,00,77,00,65,00,\
  72,00,73,00,68,00,65,00,6c,00,6c,00,5c,00,76,00,31,00,2e,00,30,00,5c,00,70,\
  00,6f,00,77,00,65,00,72,00,73,00,68,00,65,00,6c,00,6c,00,2e,00,65,00,78,00,\
  65,00,20,00,22,00,2c,00,2d,00,31,00,30,00,38,00,00,00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Microsoft.PowerShellScript.1\Shell\0\Command]
@="\"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe\" \"-Command\" \"if((Get-ExecutionPolicy ) -ne 'AllSigned') { Set-ExecutionPolicy -Scope Process Bypass }; & '%1'\""

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Microsoft.PowerShellScript.1\Shell\Edit]
"NoSmartScreen"=""

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Microsoft.PowerShellScript.1\Shell\Edit\Command]
@="\"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell_ise.exe\" \"%1\""

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Microsoft.PowerShellScript.1\Shell\Open]

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Microsoft.PowerShellScript.1\Shell\Open\Command]
@="\"C:\\Windows\\System32\\notepad.exe\" \"%1\""

 

@iworkonline 

 

Try this.

 

From:

$gpgr + ' ' + $output + ' ' + $encrypt

 

To:

Invoke-Expression "$gpgr $output $encrypt"