You don’t need to hunt for Powershell modules anymore
Have you ever been in the situation where you need to run or test some Powershell commands on a server in your environment but you cannot because you don’t have the needed Powershell module? For example, you may need to run some Powershell commands against a SQL server, Exchange server, or Web server, but you don’t have the SQLPS Powershell module or the WebAdministration module, or.. One way was to resolve this issue was to find the installation media of the application like SQL, find the Powershell module bits on it, identify, download, and install all the prerequisites, then you can use the needed PS commands.
- Microsoft® System CLR Types for Microsoft® SQL Server® 2012 (SQLSysClrTypes.msi)
- Microsoft® SQL Server® 2012 Shared Management Objects (SharedManagementObjects.msi)
- Microsoft® Windows PowerShell Extensions for Microsoft® SQL Server® 2012 (PowerShellTools.msi)
and make sure you’re getting the right x86 or x64 version for your OS.
Implicit PS remoting gives us a much simpler option. We can import module commands from the server we’re trying to manage!
Let’s follow the same example, but this time using the Import-SessionCommands function:
In PS ISE, I typed in Get-Module You can see that SQLPS is not loaded.
Trying Get-Module -ListAvailable -Name *SQL*
shows that I don’t have it on my local machine.
Now, let’s import it from the SQL server we’re trying to manage:
First import the SBTools module: Import-Module SBTools
Next import the SQLPS module commands: Import-SessionCommands -ModuleName SQLPS -ComputerName v-2012R2-SQL1 -Keep
Finally, import the Imported-SQLPS module: Import-Module Imported-SQLPS – Remember that imported modules will be prefixed with “Imported-“
Now if you type in Get-Module, you’ll see that you have the Imported-SQLPS module which has all the cmdlets (functions) from the original SQLPS module: