admin管理员组文章数量:1026989
I just ran into something useful but apparently esoteric as it's non-standard use of Get-Content; specifically: Get-Content Function:\mkdir
. When I use this command in Powershell, it returns the entire function definition, and even the function body. Oddly enough, Get-Content Function:\ipconfig
does not, even though it's listed literally alongside mkdir on the official documentation.
I've been studying ways of easily finding more info on cmdlets, object definitions, etc. in Powershell. This particular seems rather useful, however, it's hard to find more use of Get-Content in this context, as it's usually used somewhat differently.
I just ran into something useful but apparently esoteric as it's non-standard use of Get-Content; specifically: Get-Content Function:\mkdir
. When I use this command in Powershell, it returns the entire function definition, and even the function body. Oddly enough, Get-Content Function:\ipconfig
does not, even though it's listed literally alongside mkdir on the official documentation.
I've been studying ways of easily finding more info on cmdlets, object definitions, etc. in Powershell. This particular seems rather useful, however, it's hard to find more use of Get-Content in this context, as it's usually used somewhat differently.
Share Improve this question edited Nov 16, 2024 at 0:37 The-Stanislav asked Nov 16, 2024 at 0:08 The-StanislavThe-Stanislav 1342 silver badges8 bronze badges 3 |1 Answer
Reset to default 2It makes sense because md
is an alias of mkdir
and mkdir
is a function. If you target the alias:
provider then it will resolve into the command it's pointing to:
Get-Content alias:\md
In this case, I'd recommend to use Get-Command
instead if you're looking for the source code of a function.
$command = Get-Command md
$command -is [System.Management.Automation.AliasInfo] # True
$command.ResolvedCommand # mkdir
$command.ResolvedCommand.ScriptBlock # source code for mkdir
After updates to the original question the above answer doesn't make any sense. The original question was asking about an alias, and now the update is asking about an actual application (ipconfig
) which of course there is no content to get because 1. Applications don't belong to the function:
provider and 2. The source code is compiled.
I just ran into something useful but apparently esoteric as it's non-standard use of Get-Content; specifically: Get-Content Function:\mkdir
. When I use this command in Powershell, it returns the entire function definition, and even the function body. Oddly enough, Get-Content Function:\ipconfig
does not, even though it's listed literally alongside mkdir on the official documentation.
I've been studying ways of easily finding more info on cmdlets, object definitions, etc. in Powershell. This particular seems rather useful, however, it's hard to find more use of Get-Content in this context, as it's usually used somewhat differently.
I just ran into something useful but apparently esoteric as it's non-standard use of Get-Content; specifically: Get-Content Function:\mkdir
. When I use this command in Powershell, it returns the entire function definition, and even the function body. Oddly enough, Get-Content Function:\ipconfig
does not, even though it's listed literally alongside mkdir on the official documentation.
I've been studying ways of easily finding more info on cmdlets, object definitions, etc. in Powershell. This particular seems rather useful, however, it's hard to find more use of Get-Content in this context, as it's usually used somewhat differently.
Share Improve this question edited Nov 16, 2024 at 0:37 The-Stanislav asked Nov 16, 2024 at 0:08 The-StanislavThe-Stanislav 1342 silver badges8 bronze badges 3-
what is
mklink
? again, even after your update, my answer is explaining the issue.move
is also an alias not a function. instead of updating the question changing the premise of the initial question, ask a new one... – Santiago Squarzon Commented Nov 16, 2024 at 0:28 - are you going to keep editing your question until you get all the answers for all the different commands powershell can handle? – Santiago Squarzon Commented Nov 16, 2024 at 0:34
-
I'm editing to get the alias commands out, as that's not the answer I was looking for. I was trying to find out why
Get-Content Function:\mkdir
works, but so many other non-alias functions do not work with the same command. Including an alias was a simple mistake, as I've tried with dozens of others as well. – The-Stanislav Commented Nov 16, 2024 at 0:38
1 Answer
Reset to default 2It makes sense because md
is an alias of mkdir
and mkdir
is a function. If you target the alias:
provider then it will resolve into the command it's pointing to:
Get-Content alias:\md
In this case, I'd recommend to use Get-Command
instead if you're looking for the source code of a function.
$command = Get-Command md
$command -is [System.Management.Automation.AliasInfo] # True
$command.ResolvedCommand # mkdir
$command.ResolvedCommand.ScriptBlock # source code for mkdir
After updates to the original question the above answer doesn't make any sense. The original question was asking about an alias, and now the update is asking about an actual application (ipconfig
) which of course there is no content to get because 1. Applications don't belong to the function:
provider and 2. The source code is compiled.
本文标签:
版权声明:本文标题:powershell - Why "Get-Content Function:mkdir" is valid, but not "Get-Content Function:ipconfig&qu 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745670179a2162410.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
mklink
? again, even after your update, my answer is explaining the issue.move
is also an alias not a function. instead of updating the question changing the premise of the initial question, ask a new one... – Santiago Squarzon Commented Nov 16, 2024 at 0:28Get-Content Function:\mkdir
works, but so many other non-alias functions do not work with the same command. Including an alias was a simple mistake, as I've tried with dozens of others as well. – The-Stanislav Commented Nov 16, 2024 at 0:38