Why this PowerShell alias does not work?
up vote
1
down vote
favorite
I am learning PowerShell.
I would like to understand why some aliases in PowerShell 5.0 under Windows 8.1 do not work.
For instance, this command alone works:
Get-WmiObject -Class Win32_WinSAT
But it does not when defined in my $profile
as follows:
Set-Alias -Name wei -Value 'Get-WmiObject -Class Win32_WinSAT'
The error message follows:
PS C:> wei
wei : The term 'Get-WmiObject -Class Win32_WinSAT' 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
+ wei
+ ~~~
+ CategoryInfo : ObjectNotFound: (Get-WmiObject -Class Win32_WinSAT:String) , CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
EDIT:
I see the aliases work a little different than in standard Bash on Linux I am used to.
The solution was to simply declare it as a function:
Function wei { Get-WmiObject -Class Win32_WinSAT }
powershell alias
add a comment |
up vote
1
down vote
favorite
I am learning PowerShell.
I would like to understand why some aliases in PowerShell 5.0 under Windows 8.1 do not work.
For instance, this command alone works:
Get-WmiObject -Class Win32_WinSAT
But it does not when defined in my $profile
as follows:
Set-Alias -Name wei -Value 'Get-WmiObject -Class Win32_WinSAT'
The error message follows:
PS C:> wei
wei : The term 'Get-WmiObject -Class Win32_WinSAT' 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
+ wei
+ ~~~
+ CategoryInfo : ObjectNotFound: (Get-WmiObject -Class Win32_WinSAT:String) , CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
EDIT:
I see the aliases work a little different than in standard Bash on Linux I am used to.
The solution was to simply declare it as a function:
Function wei { Get-WmiObject -Class Win32_WinSAT }
powershell alias
1
Your alias equivalent to& 'Get-WmiObject -Class Win32_WinSAT'
.
– PetSerAl
Jul 19 '17 at 5:01
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am learning PowerShell.
I would like to understand why some aliases in PowerShell 5.0 under Windows 8.1 do not work.
For instance, this command alone works:
Get-WmiObject -Class Win32_WinSAT
But it does not when defined in my $profile
as follows:
Set-Alias -Name wei -Value 'Get-WmiObject -Class Win32_WinSAT'
The error message follows:
PS C:> wei
wei : The term 'Get-WmiObject -Class Win32_WinSAT' 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
+ wei
+ ~~~
+ CategoryInfo : ObjectNotFound: (Get-WmiObject -Class Win32_WinSAT:String) , CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
EDIT:
I see the aliases work a little different than in standard Bash on Linux I am used to.
The solution was to simply declare it as a function:
Function wei { Get-WmiObject -Class Win32_WinSAT }
powershell alias
I am learning PowerShell.
I would like to understand why some aliases in PowerShell 5.0 under Windows 8.1 do not work.
For instance, this command alone works:
Get-WmiObject -Class Win32_WinSAT
But it does not when defined in my $profile
as follows:
Set-Alias -Name wei -Value 'Get-WmiObject -Class Win32_WinSAT'
The error message follows:
PS C:> wei
wei : The term 'Get-WmiObject -Class Win32_WinSAT' 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
+ wei
+ ~~~
+ CategoryInfo : ObjectNotFound: (Get-WmiObject -Class Win32_WinSAT:String) , CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
EDIT:
I see the aliases work a little different than in standard Bash on Linux I am used to.
The solution was to simply declare it as a function:
Function wei { Get-WmiObject -Class Win32_WinSAT }
powershell alias
powershell alias
edited Jul 19 '17 at 10:41
asked Jul 19 '17 at 4:48
Vlastimil
1,11311333
1,11311333
1
Your alias equivalent to& 'Get-WmiObject -Class Win32_WinSAT'
.
– PetSerAl
Jul 19 '17 at 5:01
add a comment |
1
Your alias equivalent to& 'Get-WmiObject -Class Win32_WinSAT'
.
– PetSerAl
Jul 19 '17 at 5:01
1
1
Your alias equivalent to
& 'Get-WmiObject -Class Win32_WinSAT'
.– PetSerAl
Jul 19 '17 at 5:01
Your alias equivalent to
& 'Get-WmiObject -Class Win32_WinSAT'
.– PetSerAl
Jul 19 '17 at 5:01
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
Normally PowerShell tries to use the first space to separate the command from the parameters. However, you can use a string to specify that a space is just part of a file. This essentially lets you treat the space like a non-special character, and allows you to treat something like 'C:Program FilesWindows NTAccessoriesnotepad.exe' as if it was one word, not two.
That's essentially what you're doing. PowerShell cannot find a command named 'Get-WmiObject -Class Win32_WinSAT', because there is no such command. (The command in question is simply 'Get-WmiObject', not 'Get-WmiObject -Class Win32_WinSAT'.
So, I have now identified the problem. I realize I haven't provided a workaround/solution. Being that I am supposed to be at work in less than 5 hours and should get some more sleep before then, I will allow someone else that pleasure. Hopefully my comment helped identify the right track of what needed to be solved.
– TOOGAM
Jul 19 '17 at 10:10
add a comment |
up vote
1
down vote
If you like to pass other parameters to your alias, you can do this:
function wei([Parameter(ValueFromRemainingArguments = $true)]$params) {
& Get-WmiObject -Class Win32_WinSAT $params
}
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Normally PowerShell tries to use the first space to separate the command from the parameters. However, you can use a string to specify that a space is just part of a file. This essentially lets you treat the space like a non-special character, and allows you to treat something like 'C:Program FilesWindows NTAccessoriesnotepad.exe' as if it was one word, not two.
That's essentially what you're doing. PowerShell cannot find a command named 'Get-WmiObject -Class Win32_WinSAT', because there is no such command. (The command in question is simply 'Get-WmiObject', not 'Get-WmiObject -Class Win32_WinSAT'.
So, I have now identified the problem. I realize I haven't provided a workaround/solution. Being that I am supposed to be at work in less than 5 hours and should get some more sleep before then, I will allow someone else that pleasure. Hopefully my comment helped identify the right track of what needed to be solved.
– TOOGAM
Jul 19 '17 at 10:10
add a comment |
up vote
1
down vote
accepted
Normally PowerShell tries to use the first space to separate the command from the parameters. However, you can use a string to specify that a space is just part of a file. This essentially lets you treat the space like a non-special character, and allows you to treat something like 'C:Program FilesWindows NTAccessoriesnotepad.exe' as if it was one word, not two.
That's essentially what you're doing. PowerShell cannot find a command named 'Get-WmiObject -Class Win32_WinSAT', because there is no such command. (The command in question is simply 'Get-WmiObject', not 'Get-WmiObject -Class Win32_WinSAT'.
So, I have now identified the problem. I realize I haven't provided a workaround/solution. Being that I am supposed to be at work in less than 5 hours and should get some more sleep before then, I will allow someone else that pleasure. Hopefully my comment helped identify the right track of what needed to be solved.
– TOOGAM
Jul 19 '17 at 10:10
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Normally PowerShell tries to use the first space to separate the command from the parameters. However, you can use a string to specify that a space is just part of a file. This essentially lets you treat the space like a non-special character, and allows you to treat something like 'C:Program FilesWindows NTAccessoriesnotepad.exe' as if it was one word, not two.
That's essentially what you're doing. PowerShell cannot find a command named 'Get-WmiObject -Class Win32_WinSAT', because there is no such command. (The command in question is simply 'Get-WmiObject', not 'Get-WmiObject -Class Win32_WinSAT'.
Normally PowerShell tries to use the first space to separate the command from the parameters. However, you can use a string to specify that a space is just part of a file. This essentially lets you treat the space like a non-special character, and allows you to treat something like 'C:Program FilesWindows NTAccessoriesnotepad.exe' as if it was one word, not two.
That's essentially what you're doing. PowerShell cannot find a command named 'Get-WmiObject -Class Win32_WinSAT', because there is no such command. (The command in question is simply 'Get-WmiObject', not 'Get-WmiObject -Class Win32_WinSAT'.
answered Jul 19 '17 at 10:09
TOOGAM
11.3k32442
11.3k32442
So, I have now identified the problem. I realize I haven't provided a workaround/solution. Being that I am supposed to be at work in less than 5 hours and should get some more sleep before then, I will allow someone else that pleasure. Hopefully my comment helped identify the right track of what needed to be solved.
– TOOGAM
Jul 19 '17 at 10:10
add a comment |
So, I have now identified the problem. I realize I haven't provided a workaround/solution. Being that I am supposed to be at work in less than 5 hours and should get some more sleep before then, I will allow someone else that pleasure. Hopefully my comment helped identify the right track of what needed to be solved.
– TOOGAM
Jul 19 '17 at 10:10
So, I have now identified the problem. I realize I haven't provided a workaround/solution. Being that I am supposed to be at work in less than 5 hours and should get some more sleep before then, I will allow someone else that pleasure. Hopefully my comment helped identify the right track of what needed to be solved.
– TOOGAM
Jul 19 '17 at 10:10
So, I have now identified the problem. I realize I haven't provided a workaround/solution. Being that I am supposed to be at work in less than 5 hours and should get some more sleep before then, I will allow someone else that pleasure. Hopefully my comment helped identify the right track of what needed to be solved.
– TOOGAM
Jul 19 '17 at 10:10
add a comment |
up vote
1
down vote
If you like to pass other parameters to your alias, you can do this:
function wei([Parameter(ValueFromRemainingArguments = $true)]$params) {
& Get-WmiObject -Class Win32_WinSAT $params
}
add a comment |
up vote
1
down vote
If you like to pass other parameters to your alias, you can do this:
function wei([Parameter(ValueFromRemainingArguments = $true)]$params) {
& Get-WmiObject -Class Win32_WinSAT $params
}
add a comment |
up vote
1
down vote
up vote
1
down vote
If you like to pass other parameters to your alias, you can do this:
function wei([Parameter(ValueFromRemainingArguments = $true)]$params) {
& Get-WmiObject -Class Win32_WinSAT $params
}
If you like to pass other parameters to your alias, you can do this:
function wei([Parameter(ValueFromRemainingArguments = $true)]$params) {
& Get-WmiObject -Class Win32_WinSAT $params
}
answered Dec 1 at 15:10
ahmadali shafiee
1931111
1931111
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1231175%2fwhy-this-powershell-alias-does-not-work%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Your alias equivalent to
& 'Get-WmiObject -Class Win32_WinSAT'
.– PetSerAl
Jul 19 '17 at 5:01