powershell - Why "Get-Content Function:mkdir" is valid, but not "Get-Content Function:ipconfig&qu

I just ran into something useful but apparently esoteric as it's non-standard use of Get-Content;

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
Add a comment  | 

1 Answer 1

Reset to default 2

It 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745670181a4639356.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信