Getting “Can't find the drive. The drive called 'IIS' does not exist.”

前端 未结 5 1099
北恋
北恋 2020-12-01 17:45

I wrote a PowerShell script to deploy IIS Website automatically, but when I pass parameters to the script I get the following error:

Cannot find the d

相关标签:
5条回答
  • 2020-12-01 18:14

    For those on windows server 2016 and 2019 I found that it was the Server Feature

    IIS Management Console aka Web-Mgmt-Console

    that needed to be turned on. If you are in an active powershell session and have import the WebAdministration module and the command

    Get-PSDrive 
    

    does not return IIS in the list. Run the following

    Remove-Module WebAdministration
    Import-Module WebAdministration
    Get-PSDrive
    

    Then you should see the powershell IIS drive. I suspect my issue had to do with running scripts that imported WebAdministration but were attaching the PSDrive IIS in my powershell session. Attempts to import WebAdministration again would not attaching the PSDrive to my session unless I removed it first.

    0 讨论(0)
  • 2020-12-01 18:22

    The drive is provided by the WebAdministration module, so you need to install/import that module first.

    How you install the module depends on your actual system and whether you use GUI or PowerShell. On a Windows Server 2008 R2 for instance you'd install the module with the following PowerShell commands:

    Import-Module ServerManager
    Add-WindowsFeature Web-Scripting-Tools
    

    After the module is installed you can load it in your script like this:

    Import-Module WebAdministration
    
    0 讨论(0)
  • 2020-12-01 18:28

    To resolve running the script (or powershell shell/exe) in Admin mode.

    0 讨论(0)
  • 2020-12-01 18:29

    On Windows Server 2008 32-bit, I had to explicitly download and install "IIS Powershell Snap-in (x86)" from Microsoft's website.

    0 讨论(0)
  • 2020-12-01 18:35

    I was facing the same problem while trying to run a script in PowerShell ISE.

    The problem was fixed when I reopened PowerShell ISE as Administrator.

    0 讨论(0)
提交回复
热议问题