Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Installing, importing and using any module in powershell

With Powershell you can achieve great way to automation using additional modules. Modules are additional functionalities or extensions to Powershell. You can also treat them as client softwares, with them you can connect to particular softwares, You will see limitation if you want additional commands and modules does not exist. After installing them you can use related .net objects or adapters. Four types are Powershell modules exist Script, Binary, Manifest, Dynamic. For more detailed information read Microsoft official article. 

For more on using script check Different ways to bypass Powershell execution policy :.ps1 cannot be loaded because running scripts is disabled

To demonstrate I will take example of ActiveDirectory module. To install it use, Search and open Server Manager, in the Manage, click Add Roles and Features. From Select Features menu, expand Remote Server Administration Tools, Under Role Administration Tools, Select all AD DS and AD LDS tools and Install softwares. Same way you can install other modules and tools from list ie DHCP, Hyper-V and etc, these steps are for Windows 2016 server. If you need it on Windows 10, separate RSAT tools need to be downloaded and installed.

Once Active Directory modules for windows PowerShell installed successfully. Same can be searched in find and open it. Module is already imported on the console. To verify the list of loaded modules run command Get-Module, ActiveDirectory module is in the list. To view what commands are associated to AD use command Get-Command -Module ActiveDirectory. Again to verify everything is OK, I am running one of the AD command Get-ADUser vkunal.

Next step is helpful when you want to run active directory command from normal PowerShell console. By default these steps are not required for newer versions of PowerShell above v4. As whenever you run related commands ie Get-AdUser, module will automatically loaded it exists on machine. But if you want to manually import it run Import-Module ActiveDirectory. It is a best practice while writing script import module first instead of depend on auto loading of module.

If you want to list of all the installed modules you can run command Get-Module -ListAvailable.

There might be a scenario, your required modules will not exist in RSAT tools and needs to find it online with Find-Module. This requires active internet. It will show all community and official modules in the list from online repositories. To download required module use command Install-Module ModuleName.

Module files can be directly copied to modulepath, Path can be viewed using inbuilt command $env:PSModulePath -split ';'. There are 3 default paths. 
C:\Program Files\WindowsPowerShell\Modules

I have copy-pasted files to first location C:\Users\username\Documents\WindowsPowerShell\Modules, If path does not exist create folders. Note my module folder name and psm1 file has same name and it should be that way to Import it. If in-case you have psm1 module in another location simply provide a file path while importing it. For this step administrator rights are not required.

One of the other way to extend Powershell is install 3rd party software check VMWARE VSPHERE POWERCLI INSTALLATION AND CONFIGURATION STEP BY STEP.

Useful articles
Active Directory Powershell: Create bulk users from CSV file

This post first appeared on Tales From Real IT System Administrators World And Non-production Environment, please read the originial post: here

Share the post

Installing, importing and using any module in powershell


Subscribe to Tales From Real It System Administrators World And Non-production Environment

Get updates delivered right to your inbox!

Thank you for your subscription