- 1 year ago
"Get-IISAppPool" not recognised when script is run via Invoke-Command in Powershell
When using Invoke-Command
in PowerShell to run a script remotely, the remote system may not have the same PowerShell modules or commands available as the local system. This can result in the "Get-IISAppPool" cmdlet not being recognized when executed via Invoke-Command
.
To resolve this issue, you can try the following steps:
Ensure the module is installed: Verify that the module containing the "Get-IISAppPool" cmdlet is installed on the remote system. In this case, you need the IISAdministration module, which provides cmdlets for managing IIS (Internet Information Services). If the module is not installed, you can install it using the
Install-Module
cmdlet.On the remote system, open a PowerShell session and run the following command to install the IISAdministration module:
powershellInstall-Module -Name IISAdministration
Import the module: In your script, include the
Import-Module
cmdlet to load the IISAdministration module before using the "Get-IISAppPool" cmdlet. This ensures that the required cmdlets are available for execution. Modify your script to include the following line at the beginning:powershellImport-Module -Name IISAdministration
Use the fully qualified cmdlet name: If the module is already installed on the remote system, but the cmdlet is still not recognized, you can try using the fully qualified name of the cmdlet. The fully qualified name includes the module name and the cmdlet name, separated by a backslash. Modify your script to use the following command instead:
powershellIISAdministration\Get-IISAppPool
This explicitly specifies the module that contains the "Get-IISAppPool" cmdlet.
By ensuring that the IISAdministration module is installed and imported on the remote system, or using the fully qualified cmdlet name, you should be able to use the "Get-IISAppPool" cmdlet successfully when executing your script via Invoke-Command
in PowerShell.