Error in running CTRL+C Powershell script in Powershell.exe - powershell

I want to run a Powershell code in Powershell.exe.
When I type in
Copy-Item c:\test\my_file.txt C:\Test\testPSHELL
it works fine.
When I copy it and then paste it, I get
^V
which is normal. But after excecuting I get error:
The term '▬' 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 line:1 char:1
Dont you know where can be the problem? I am getting upset :D

The reason you got that error is that Ctrl-C is the interrupt command for PowerShell. If you have a long running command that you want to interrupt before it finishes, pressing Ctrl-C will kill the command (This is the same for Linux shells like bash, zsh, etc.)

Related

Trying to escape parenthesis when passing arguments in a PowerShell script

I made a PowerShell script that will send a toast notification via/arguments. In the script, I use the param function in the beginning of the script something like....this
param($UserID)
Now I open a command prompt to load a PowerShell script and adding these arguments
powershell C:\file\in\directory\PowershellScript.ps1 -UserID "Mikey (TEST)"
When I sent the prompt over to PowerShell, it gave me this red error that says
TEST : The term 'TEST' 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 line:1 char:64
Assumingly the parentheses ( ) could be the culprit as PowerShell is thinking of loading a module of some sort instead of applying as a string value. I even tried escaping the parentheses using the backslash \(TEST\) but that didn't work either as it said TEST\ : The term 'TEST\' is not recognized as the name of a cmdlet, function, script file, or operable program..
Is there something I'm missing or something part of a script I should add to?
Use single quotes inside the ps command:
powershell C:\file\in\directory\PowershellScript.ps1 -UserID 'Mikey (TEST)'

Powershell doesn't recognize openssl even after I added it to the system path

I am on a 64bit Windows 10. I installed Win64 OpenSSL v1.1.0f and added the install directory C:\OpenSSL-Win64\bin to my system PATH.
Upon running it in cmd or Powershell, I get:
openssl : The term 'openssl' 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.
What else am I missing?
If you're running it in Powershell, check $env:path to be sure "C:\OpenSSL-Win64\bin" is in there. Previous comments all reference the PATH variable in in cmd.exe, which your error message suggests you are not using.
If it is not, run the following command in Powershell:
$env:path = $env:path + ";C:\OpenSSL-Win64\bin"
May be you need to close the session and open a new powershell, whenever you make changes to env variable it does not work on current session.

Writing my first powershell script: commands are not recognized in the script

rename-item A B
When typed in the shell, and provided there is a file A at the local directory, the rename works.
When I write a one-line script, put it in a folder, export the path to this folder, go to another folder, containing a file A, and call the script, here is what happens:
'rename-item' is not recognized as an internal or external command,
operable program or batch file.
What am I missing?
When you ran the batch file, you were calling a batch file that had PowerShell commands in it. The command prompt was directing its output through Powershell, which was the above errors. Command.exe cannot run powershell cmdlets, so when it got to Rename-Item, it was not a good internal or external command, operable program or batch file.
Ping.exe is called when you Ping www.google.com for example of what is a good command or executable.
Powershell can run commands from command.exe, the reverse is not true.
You can see the same result if you open a cmd prompt and try to run powershell commands or cmdlets.:
H:\>rename-item 'rename-item' is not recognized as an internal or external command,
operable program or batch file.

Running Powershell script from SSIS with OnTap cmdlets throws error, but not when run from PS Cmd Line?

We are trying to run a Poweshell Script that uses the OnTap PS Modules, from SSIS, when we do, an error is issued:
Error: The term 'Connect-NaController' 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.
But when we run the same script from the Powershell Command Line, then the script runs just fine. So I think the scripts are fine.
So I'm wondering if the security context is different or we have to do something more explicitly in our call from SSIS?
When we call the script from SSIS we use: -ExecutionPolicy ByPass
Thanks!
In SSIS i had to set the FULL PATH of the script instead of ./scriptfile

How Can I Get PowerShell to Execute MpCmdRun.exe

PowerShell runs programs such as IpConfig and WhoAmI just as cmd would. However, I am stumped trying to run MpCmdRun.exe
Clear-Host
Set-Location "C:\Program Files\Windows Defender"
Get-ChildItem
mpcmdrun.exe
Result
Error:
mpcmdrun.exe : The term 'mpcmdrun.exe' is not recognized as the name of a cmdlet, function, script file, or operable
program.
You are doing mpcmdrun.exe. You have to do .\mpcmdrun.exe as the current folder . is not in PATH in Powershell unlike in cmd.
PS:
I wonder if you read the entire message that Powershell would have spit out when you did as you said:
Suggestion [3,General]: The command MpCmdRun.exe was not found, but
does exist in the current location. Windows PowerShell does not load
commands from the current location by default. If you trust this
command, instead type ".\MpCmdRun.exe". See "get-help
about_Command_Precedence" for more details.
PPS:
The other commands ran because they were in PATH.