Powershell alias that open the desktop, but keep getting error

twinbaby

Supremacy Member
Joined
Jul 8, 2014
Messages
5,417
Reaction score
1,499
I would like to create a powershell alias that open the deskop. But I keep getting error. Do advise.

New-Alias -Name odesk -Value { Start-Process -Path "C:\Users\xxx\xxxx\Desktop" }
New-Alias : Cannot evaluate parameter 'Value' because its argument is specified as a script block and there is no
input. A script block cannot be evaluated without input.
At line:1 char:30
+ ... desk -Value { Start-Process -Path "C:\Users\xxxx\xxxxx ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : MetadataError: :)) [New-Alias], ParameterBindingException
+ FullyQualifiedErrorId : ScriptBlockArgumentNoInput,Microsoft.PowerShell.Commands.NewAliasCommand
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,301
I would like to create a powershell alias that open the deskop. But I keep getting error. Do advise.

New-Alias -Name odesk -Value { Start-Process -Path "C:\Users\xxx\xxxx\Desktop" }
Not savvy in Powershell.

Code:
Function Get-Desktop { (New-Object -ComObject shell.application).toggleDesktop() }
Set-Alias -name odesk -Value Get-Desktop

Code:
Function Open-Desktop { Start-Process -FilePath "$HOME\Desktop" }
Set-Alias -name odesk -Value Open-Desktop
 
Last edited:

twinbaby

Supremacy Member
Joined
Jul 8, 2014
Messages
5,417
Reaction score
1,499
Code:
Function Open-Desktop { Start-Process -FilePath "$HOME\Desktop" }
Set-Alias -name odesk -Value Open-Desktop

@davidktw

This works! Tyvm

I am trying to create a Windows environment like Linux using command line whereby I can navigate around folder easily.
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,301
Code:
Function Open-Desktop { Start-Process -FilePath "$HOME\Desktop" }
Set-Alias -name odesk -Value Open-Desktop

@davidktw

This works! Tyvm

I am trying to create a Windows environment like Linux using command line whereby I can navigate around folder easily.
There could be a way to set alias to an anonymous function, which I haven't figure out if it is possible. Perhaps someone savvy in Powershell comes along may advise.

:)
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,301
There could be a way to set alias to an anonymous function, which I haven't figure out if it is possible. Perhaps someone savvy in Powershell comes along may advise.

:)
@twinbaby

Found this method works too
Code:
Function Open-Desktop
{
  [Alias("odesk")]
  PARAM()
  Start-Process -FilePath "$HOME\Desktop"
}

:)
 

twinbaby

Supremacy Member
Joined
Jul 8, 2014
Messages
5,417
Reaction score
1,499
Set-Alias -Name vmware -Value "C:\Program Files (x86)\VMware\VMware Workstation\vmware.exe" -Option AllScope

Above is an example,

I am trying to do something like vmwareubuntu and vmwarewindows without having to type vmware -x "Ubuntu 64-bits" and vmware -x "Ubuntu -x Windows 10" all the time

But it seems that powershell can't reference another alias.
 
Last edited:

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,301
Set-Alias -Name vmware -Value "C:\Program Files (x86)\VMware\VMware Workstation\vmware.exe" -Option AllScope

Above is an example,

I am trying to do something like vmwareubuntu and vmwarewindows without having to type vmware -x "Ubuntu 64-bits" and vmware -x "Ubuntu -x Windows 10" all the time

But it seems that powershell can't reference another alias.
I thought I already show you the alternatives of how you declare Function and also alias. In fact all you need to do is to wrap around your command in a Function and then just create an alias to the Function.
Code:
Function Open-Desktop
{
  [Alias("odesk")]
  PARAM()
  Start-Process -FilePath "$HOME\Desktop"
}

Code:
Function Vmware-Ubuntu
{
  [Alias("vmwareubuntu")]
  PARAM()
  C:\Program Files (x86)\VMware\VMware Workstation\vmware.exe -x "Ubuntu 64-bits"
}

I found this online and tried modifying it, works too
Code:
function Testfunct{
  [Alias("testing")]
  param(
    [Parameter (Mandatory = $false)] [String]$Name
  )
  Write-Output "Name : $name"
}

> testing -Name abc
Name : abc

Might not be exactly correct above, but you can work around it for the program file paths.
:)
 

twinbaby

Supremacy Member
Joined
Jul 8, 2014
Messages
5,417
Reaction score
1,499
I thought I already show you the alternatives of how you declare Function and also alias. In fact all you need to do is to wrap around your command in a Function and then just create an alias to the Function.
Code:
Function Open-Desktop
{
  [Alias("odesk")]
  PARAM()
  Start-Process -FilePath "$HOME\Desktop"
}

Code:
Function Vmware-Ubuntu
{
  [Alias("vmwareubuntu")]
  PARAM()
  C:\Program Files (x86)\VMware\VMware Workstation\vmware.exe -x "Ubuntu 64-bits"
}

I found this online and tried modifying it, works too
Code:
function Testfunct{
  [Alias("testing")]
  param(
    [Parameter (Mandatory = $false)] [String]$Name
  )
  Write-Output "Name : $name"
}

> testing -Name abc
Name : abc

Might not be exactly correct above, but you can work around it for the program file paths.
:)
x86 : The term 'x86' 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\alvoo\OneDrive - Visa Inc\Desktop\script.ps1:65 char:21
+ C:\Program Files (x86)\VMware\VMware Workstation\vmware.exe -x "Ubu ...
+ ~~~
+ CategoryInfo : ObjectNotFound: (x86:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
 

twinbaby

Supremacy Member
Joined
Jul 8, 2014
Messages
5,417
Reaction score
1,499
Start-Process "C:\Program Files (x86)\VMware\VMware Workstation\vmware.exe" -ArgumentList '-x'

I am confused by this syntax as well
 
Important Forum Advisory Note
This forum is moderated by volunteer moderators who will react only to members' feedback on posts. Moderators are not employees or representatives of HWZ Forums. Forum members and moderators are responsible for their own posts. Please refer to our Community Guidelines and Standards and Terms and Conditions for more information.
Top