1

My PowerShell environment has two Expand-Archive commands:

  • Windows 10 -> a function from Microsoft.PowerShell.Archive (1.0.1.0)
  • PowerShell Community Extension -> a CmdLet from Pscx (3.2.2)

My current environment defaults to the CmdLet from Pscx:

PS> (Get-Command Expand-Archive).ModuleName
Pscx

Is there any syntax (fully qualified name) to call a command from another module?
I do not want to unload Pscx.

Paebbels
  • 15,573
  • 13
  • 70
  • 139

1 Answers1

3

You can always call a function with its fully-qualified module name.

In your example:

Microsoft.PowerShell.Archive\Expand-Archive -Path $Path -Destination $Dest

I think when you don't specify the module, it uses whatever was loaded last

Maximilian Burszley
  • 18,243
  • 4
  • 34
  • 63
  • 1
    You could even alias that to something less cumbersome. – EBGreen Dec 29 '17 at 15:51
  • @EBGreen: You can, but then you're introducing another point of failure. If I suspect I have a polluted environment, I'd full-path everything in a script (since it's only being written once). Fun-fact: I've had some servers with no environment variables and altered built-in modules. – Maximilian Burszley Dec 29 '17 at 15:54
  • I would full path everything in a script too. I was thinking of working at the prompt which is where I spend a lot of my time. – EBGreen Dec 29 '17 at 15:58
  • @EBGreen that makes sense. I spend most of my time automating deployments/configs and writing scripts – Maximilian Burszley Dec 29 '17 at 17:20