I am trying to run Exchange PowerShell Commands through windows Command Prompt.
I searched for the same and found
powershell.exe -command Get-mailbox
which results into the following error
The term 'get-mailbox' is not recognized as the name of a cmdlet, function, scr
ipt 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:12
+ get-mailbox <<<<
+ CategoryInfo : ObjectNotFound: (get-mailbox:String) [], Command
NotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I found one more way that is creating a .ps1 file.so I created a .ps1 file named A.ps1 having one System command(Copy that is running successfully) and one exchange command
it again results into the same like above error.
note: I am running cmd as an elevated user only.
I don't know where i am going wrong.
I also found many other commands but each results into the same error (command not recognized as cmdlet..)
Any help or suggestions would be greatly appreciated
Thanks!
The exchange commands don't work in a normal Powershell console, you need to first establish a connection to your Exchange Server. The code example in the linked TechNet article will ask the user to input the credentials to connect to the exchange server. If you would like to "save" the credentials I would recommend to encrypt your credentials and don't save it in clear text in your script! For an example see this two part Blog article from PDQ.
Related
I have this problem when I'm using Voicemeeter and Discord together, my voice is just crackling and cutting out. I found out the solution to this problem. It's by going to the task manager, heading to details, right clicking audiodg.exe, and then setting it's affinity to only one processer. The problem is I don't want to do this all by hand everytime I start my computer. Is there any way I can write a line of code into the cmd that changes this? This way I can save this lane as a bat file and then put it into the shell:startup and everytime I turn my computer on it will do it automatically for me.
Thank you so much in advance.
Edit:
I'm sorry I wasn't aware of that. This is the error I get:
C:\Users\borah>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
"$Process = Get-Process audiodg.exe; $Process.ProcessorAffinity=1"
Get-Process : Cannot find a process with the name "audiodg.exe".
Verify the process name and call the cmdlet again. At line:1 char:12
$Process = Get-Process audiodg.exe; $Process.ProcessorAffinity=1
~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : ObjectNotFound: (audiodg.exe:String) [Get-Process], ProcessCommandException
FullyQualifiedErrorId : NoProcessFoundForGivenName,Microsoft.PowerShell.Commands.GetProcessCommand
The property 'ProcessorAffinity' cannot be found on this object.
Verify that the property exists and can be set. At line:1 char:37
$Process = Get-Process audiodg.exe; $Process.ProcessorAffinity=1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : InvalidOperation: (:) [], RuntimeException
FullyQualifiedErrorId : PropertyNotFound
You can set affinity by typing a command, like following,
Start /affinity 2 notepad
This will start notepad while setting an affinity to second core of CPU.
You can save the command above in a file ending with .cmd and run it by double clicking like any other application. Or you can use task scheduler to launch it with windows startup every time, or you can run it as a startup application.
Edit
If you meant changing affinity of an already running process. Check Mofi's comment as solution.
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe "$Process = Get-Process audiodg; $Process.ProcessorAffinity=1"
I have had to uninstall and then reinstall miniconda. After reinstalling, when I run, the powershell prompt shows the following message:
& : The term 'C:\Users\jenj0\anaconda3\Scripts\conda.exe' 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 C:\Users\jenj0\Documents\WindowsPowerShell\profile.ps1:4 char:4
+ (& "C:\Users\jenj0\anaconda3\Scripts\conda.exe" "shell.powershell" "h ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\Users\jenj0\...ripts\conda.exe:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
(base) PS C:\Users\jenj0>
Additionally, the miniconda command prompt window doesn't launch at all.
I tried looking for solutions. For example, I tried this, but when I try to launch cmd.exe, I see a quick flash of a window opening and then closing and nothing happens.
I have also tried uninstalling/reinstalling miniconda again and had the same issue. I was doing that because I was having issues to run a program. Now I am even further away from solving the problem.
There is some invalid paths in the startup scripts for powershell and also the registry keys for cmd, stemming from your previous anaconda installation.
You say that you uninstalled anaconda and then installed miniconda, so I am assuming that the path
C:\Users\jenj0\anaconda3
does not exist and is now
C:\Users\jenj0\miniconda3
Here is what you do:
Powershell (from your error message) is trying to read C:\Users\jenj0\Documents\WindowsPowerShell\profile.ps1 which contains references to the invalid path. Backup said file and then delete any lines that contain the invalid path
cmd (and anaconda prompt). Run regedit and then delete the reference to the invalid path in the keys at
Computer\HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun
Computer\HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun
I'm executing remotely some scripts to get information from a server, using Plink tool from putty. The trouble comes when I use a .ps1 file, because one '?' appears on the beginning, making the first line incorrect, but with .bat files works as desired.
For example, I want to print the content of a file:
GetDate.bat:
type C:/Data/DateOfCompilation.txt
And then:
PS C:/Users/MyUser> plink -ssh <User>#<IP> -i C:\Key.ppk -m C:\Scripts\GetDate.bat
10/09/2018 14:32:02,72
Everything okay
GetDate.ps1:
Get-Content -Path C:/Data/DateOfCompilation.txt
Execution:
PS C:/Users/MyUser> plink -ssh <User>#<IP> -i C:\Key.ppk -m C:\Scripts\GetDate.ps1
?Get-Content : The term '?Get-Content' 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
+ ?Get-Content -Path C:/Data/DateOfCompilation.txt
+ ~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (?Get-Content:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Also, if I add more code, the other lines work fine, it's just the first one which fails with that '?' added at the beginning.
(However, running locally the script works fine)
I have other ps1 scripts much more extended, so using only bat files is not the best option.
I have looked at the documentation, other forums and here, but I'm not able to find anything. Maybe I do not know anything about ps1 files.
Check if there's UTF-8 BOM at the beginning of GetDate.ps1 - If there is, remove it.
Though the root cause your problem may be your misunderstanding of that -m switch of Plink does. It makes Plink read the file and send its contents (and only the contents) to the server. The server never learns, what the file extension is. So it makes no sense to use .ps vs .bat. No matter, what the extension is, the file will be interpreted by the default shell of your Windows SSH server. What is PowerShell (according to the error message).
So even your type command in .bat file was executed by PowerShell, not by cmd.exe. In PowerShell, type is an alias to Get-Content.
The reason why your .bat file works is most probably that it has no BOM, while your .ps1 has BOM. Had you executed your .ps1 with PowerShell, it would handle the BOM correctly. But you are not executing .ps1 with PowerShell, you are executing its contents, and in that case the BOM probably causes problems.
The difference is basically like between:
powershell.exe -File GetDate.ps1
and
powershell.exe < GetDate.ps1
Both do basically the same, but the latter fails with BOM, while the first handles it correctly.
This is the exact error on the cmd window.
this is the command I typed to be executed in the cmd
F:\Fast R-CNN\Cognitive tool kit\cntk\Scripts\install\windows>install.bat
CNTK Binary Install Script
F:\Fast : The term 'F:\Fast' 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
+ F:\Fast R-CNN\Cognitive tool kit\cntk\Scripts\install\windows\ps\inst ...
+ ~~~~~~~
+ CategoryInfo : ObjectNotFound: (F:\Fast:String) [], CommandNotF
oundException
+ FullyQualifiedErrorId : CommandNotFoundException
Error during install operation
I've tried running as admin, direct clicking, changing the path etc. Kindly tell me a way to run this file. It's a batch file for a series of installations for the Microsoft cognitive tool kit.
Looks like you need to enclose the path in quotes
"F:\Fast R-CNN\Cognitive tool kit\cntk\Scripts\install\windows\install.bat"
use "start" before the filename.
Example:
F:\Fast R-CNN\Cognitive tool kit\cntk\Scripts\install\windows>start install.bat
I'm having some issues with dnvm.
The error that is displaying is this:
D:\development\Disqorse>dnvm use 1.0.0.-rc1-final
Cannot find dnx-clr-win-x86.1.0.0.-rc1-final, do you need to run 'dnvm install
1.0.0.-rc1-final'?
At C:\Users\Jonathan Smith\.dnx\bin\dnvm.ps1:1667 char:9
+ throw "Cannot find $runtimeFullName, do you need to run '$Com ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (Cannot find dnx....0.-rc1-final'?:St
ring) [], RuntimeException
+ FullyQualifiedErrorId : Cannot find dnx-clr-win-x86.1.0.0.-rc1-final, do you ne
ed to run 'dnvm install 1.0.0.-rc1-final'?
'C:\Users\Jonathan' is not recognized as an internal or external command,
operable program or batch file.
The system cannot find the path specified.
But when I run the above commands and try suggestions from SO I still get the same issue. Also interesting is the fact that after I carry out ANY commands I get the text at the bottom complaining there is a non-recognized command. I susepect this is because there is a space in the folder name which represents the current user. I can't be sure whether this is the problem or not though.
Check script execution permission level in your powershell window. I set it to remote signed using:
Set-ExecutionPolicy RemoteSigned
Also, you need to supply the runtime and architecture as well:
like dnvm use 1.0.0-rc1-update1 -r clr -arch x64
Your version of dnvm has a bug and does not work when user name contains spaces.
One of the proposed solutions is to self-update it using
dnvm update-self
And if that does not work, try using new command-line interface that replaces dnvm. You can read about it in more details here - https://github.com/aspnet/dnvm/issues/190 (bottom posts)