PowerShell – IIS automation

You can view the IIS gui conole by running “Inetmgr” on the commandline.


You can find all my latest posts on medium.



To automate IIS you first need to ensure you have the “webadministration”:


PS C:\Windows\system32> Get-Module -ListAvailable

Directory: C:\Windows\system32\WindowsPowerShell\v1.0\Modules

ModuleType Version Name ExportedCommands
———- ——- —- —————-
Manifest ADRMS {Update-ADRMS, Uninstall-ADRMS, Install-ADRMS}
Manifest AppLocker {Set-AppLockerPolicy, Get-AppLockerPolicy, Test-AppLockerP…
Manifest 1.0 BestPractices {Get-BpaModel, Invoke-BpaModel, Get-BpaResult, Set-BpaResult}
Manifest BitsTransfer {Add-BitsFile, Remove-BitsTransfer, Complete-BitsTransfer,…
Manifest CimCmdlets {Get-CimAssociatedInstance, Get-CimClass, Get-CimInstance,…
Script ISE {New-IseSnippet, Import-IseSnippet, Get-IseSnippet}
Manifest Microsoft.PowerShell.Diagnostics {Get-WinEvent, Get-Counter, Import-Counter, Export-Counter…
Manifest Microsoft.PowerShell.Host {Start-Transcript, Stop-Transcript}
Manifest Microsoft.PowerShell.Management {Add-Content, Clear-Content, Clear-ItemProperty, Join-Path…
Manifest Microsoft.PowerShell.Security {Get-Acl, Set-Acl, Get-PfxCertificate, Get-Credential…}
Manifest Microsoft.PowerShell.Utility {Format-List, Format-Custom, Format-Table, Format-Wide…}
Manifest Microsoft.WSMan.Management {Disable-WSManCredSSP, Enable-WSManCredSSP, Get-WSManCredS…
Binary 1.0 PSDesiredStateConfiguration {Set-DscLocalConfigurationManager, Start-DscConfiguration,…
Script PSDiagnostics {Disable-PSTrace, Disable-PSWSManCombinedTrace, Disable-WS…
Binary PSScheduledJob {New-JobTrigger, Add-JobTrigger, Remove-JobTrigger, Get-Jo…
Manifest PSWorkflow {New-PSWorkflowExecutionOption, New-PSWorkflowSession, nwsn}
Manifest PSWorkflowUtility Invoke-AsWorkflow
Manifest ServerManager {Get-WindowsFeature, Add-WindowsFeature, Remove-WindowsFea…
Manifest TroubleshootingPack {Get-TroubleshootingPack, Invoke-TroubleshootingPack}
Manifest WebAdministration {Start-WebCommitDelay, Stop-WebCommitDelay, Get-WebConfigu…

Directory: C:\Program Files\System Center Operations Manager\Agent\PowerShell

ModuleType Version Name ExportedCommands
———- ——- —- —————-
Binary Microsoft.MonitoringAgent.PowerS… {Checkpoint-WebApplicationMonitoring, Get-WebApplicationMo…

PS C:\Windows\system32>


If you have windows 2008 with IIS 7.5 installed, then you should see a module called “WebAdministration”. Next do:


Import-Module -Name WebAdministration

After that you should have a bunch of IIS related commands ready for use:

PS C:\Windows\system32> Get-Command -Module webadministration

CommandType Name ModuleName
———– —- ———-
Alias Begin-WebCommitDelay webadministration
Alias End-WebCommitDelay webadministration
Function IIS: webadministration
Cmdlet Add-WebConfiguration webadministration
Cmdlet Add-WebConfigurationLock webadministration
Cmdlet Add-WebConfigurationProperty webadministration
Cmdlet Backup-WebConfiguration webadministration
Cmdlet Clear-WebConfiguration webadministration
Cmdlet Clear-WebRequestTracingSettings webadministration
Cmdlet ConvertTo-WebApplication webadministration
Cmdlet Disable-WebGlobalModule webadministration

Along with this you should have the IIS drive available too:

[powershell] PS C:\Windows\system32> psdrive Name Used (GB) Free (GB) Provider Root CurrentLocation —- ——— ——— ——– —- ————— A FileSystem A:\ Alias Alias C 30.80 19.10 FileSystem C:\ Windows\system32 Cert Certificate \ D FileSystem D:\ Env Environment Function Function HKCU Registry HKEY_CURRENT_USER HKLM Registry HKEY_LOCAL_MACHINE IIS WebAdminis… \\OSVM1043 Variable Variable WSMan WSMan [/powershell]

 Create a Virtual Directory

You need to use the New-WebVirtualDirectory command:


Here is an example command:

New-WebVirtualDirectory -Name “xxx”   -site “Default Web Site” -PhysicalPath ‘C:\Program Files\path\to\folder’


Name – This is the name as you want it to when viewing it in the Inetmgr’s tree structure.

Sites – on the inetmgr gui, it is the parent too the name, within the tree.

physicalpath – it is the full path to the folder where the folder should reside. For consistency it might be a good idea to mirror the folder’s name with the “name”







After this, you should see IIS when you do:


Also you should see the following new commands:

Get-Command -Module webadministration