I try to start powershell as an external tool.
I want it to be run in the console windows of eclipse.
But it starts with empty console, and when I type and press return, I get:
Missing expression after unary opearator ‘-’.
At line:1 char:2
+ – <<<< Command Set-Location C:\Users\XXX
+ CategoryInfo : ParserError: (-:String) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingExpressionAfterOperator
You got misplaced quotes in the Arguments section.
-NoExit -"Command Set-Location ${project_loc}"
Try moving the quote after Command switch like so,
-NoExit -Command "Set-Location ${project_loc}"
Related
Amateur computer science student here.
Trying to activate a virtual environment in powershell and I keep
getting the following error both when I start powershell or try to
activate the environment. The environment opens normally in CMD.
I've tried reinstalling to no avail. Not sure what to do so making a first post on StackOverflow.
Many thanks and kind regards,
Daniel
PS C:\Users\User> conda activate MyDjangoEnv
Invoke-Expression : At line:1 char:1342
... iles\PuTTY;"C:\Users\User\AppData\Local\Packages\PythonSoftwareFounda ...
Unexpected token 'C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\loc
al-packages\Python39\Scripts' in expression or statement.
At C:\Users\User\anaconda3\shell\condabin\Conda.psm1:76 char:9
+ Invoke-Expression -Command $activateCommand;
+ CategoryInfo : ParserError: (:) [Invoke-Expression], ParseException
+ FullyQualifiedErrorId : UnexpectedToken,Microsoft.PowerShell.Commands.InvokeExpressionCommand
Trying to create a here-string
> $scriptblock =#'
The string is missing the terminator: '#.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
Why am I getting this in the Powershell ISE, but it works normally in Powershell?
Version 5.1.
> $scriptblock =#'
>>
No, there's no space after the single-quote. I just hit enter.
I even closed and reopened ISE and same thing.
Answer provided by Mathias R. Jessen:
Press [Shift+Enter] to insert a literal newline in the ISE console
I'm trying to execute the following NuGet add command via a PowerShell script:
Invoke-Expression "'C:\Program Files\NuGet\nuget.exe' add '\packageName.1.1.0.nupkg' -Source '\\file-server\My Nuget Packages'"
However, I keep running into the following errors:
Invoke-Expression : At line:1 char:36
+ 'C:\Program Files\NuGet\nuget.exe' add '\packageName.1.1.0.nupkg' -Source '\\fil ...
+ ~~~
Unexpected token 'add' in expression or statement.
At line:3 char:1
+ Invoke-Expression "'C:\Program Files\NuGet\nuget.exe' add '\packageName.1.1.0.nu ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ParserError: (:) [Invoke-Expression], ParseException
+ FullyQualifiedErrorId : UnexpectedToken,Microsoft.PowerShell.Commands.InvokeExpressionCommand
Is there a way to call the Nuget add script from within Powershell? If so, how would I do so?
Replace Invoke-Expression with & and remove the double quotes surrounding command line, and change single quotes to double quotes:
& "C:\Program Files\NuGet\nuget.exe" add "\packageName.1.1.0.nupkg" -Source "\\file-server\My Nuget Packages"
Although I suspect that \packageName.1.1.0.nupkg should really be .\packageName.1.1.0.nupkg
I can run any PowerShell command inside AHK file. For example, this command below:
Run, PowerShell.exe -noexit -Command "Start notepad; start calc.exe",, hide
I have Powershell command that I can run it from PowerShell fine and its working great which will add user as local admin on remote machine:
([ADSI]"WinNT://serverabc123/Administrators,Group").Add("WinNT://HMM.org.br/Paul1")
However, when I use the above code on AHK like it's not working!
Run, PowerShell.exe -noexit -Command "([ADSI]"WinNT://serverabc123/Administrators,Group").Add("WinNT://HMM.org.br/Paul1")",, hide
I keep getting this error:
At line:1 char:8<>
+ ([ADSI]WinNT://serverabc123/Administrators
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected token 'WinNT://serverabc123/Administrators' in expression or statement.
At line:1 char:8
+ ([ADSI]WinNT://serverabc123/Administrators
+ ~
Missing closing ')' in expression.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken
Can anyone advice on what to do? I could write external file PS1 and call it from the AHK then delete it, but I want to have it running from my single AHK file.
Try the following:
Run, powershell.exe -noexit -command ([ADSI]\"WinNT://serverabc123/Administrators`,Group\").Add(\"WinNT://HMM.org.br/Paul1\")
That is:
Don't use outer quoting.
\-escape " characters (required by PowerShell)
`-escape , characters (required by AutoHotkey)
Set-ExecutionPolicy : Access to the registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\
PowerShell\1\ShellIds\Microsoft.PowerShell' is denied.
At line:1 char:20
+ Set-ExecutionPolicy <<<< Unrestricted
+ CategoryInfo : NotSpecified: (:) [Set-ExecutionPolicy], UnauthorizedAcce
ssException
+ FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.C
ommands.SetExecutionPolicyCommand
Is there any way to bypass this? Or at least run my powershell code? Please help!
you can do the following,
PowerShell.exe -ExecutionPolicy Bypass -File .runme.ps1
and run this in a cmd prompt
or copy and paste the whole script in a PS Console