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

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.

本文标签: