Tuesday, May 22, 2012

Import only specific Cmdlets from Module in Powershell.



Sometime in Scripts we imported whole module but we need only we cmdlets of that module. For example i am working on a script which run on "Active Directory",  but in "Active Directory" module i am using only two cmdlets Get-ADUser,Get-ADGroup , so it seems wise if we able to import only these cmdltes rather then whole bunch of other Cmdlets which we are not going to use in the script.

we can do this using -Cmdlet parameter in Import-Module Cmdlet,

Import-Module ActiveDirectory -Cmdlet Get-ADUser,Get-ADGroup

Now we are importing only two cmdlets  Get-ADUser,Get-ADGroup from "Active Directory" Module.

22-05-2012 11-13-29

Ok, Module imported successfully now check which cmdlets "Active Directory" have { i already show you how to do this here }

Get-Command -Module ActiveDirectory

22-05-2012 11-13-40

Yo!!!, Module have has only two Cmdlets which we told him to import.

Cool!! Isn't.

Thanks for reading.

Aman Dhally


No comments:

Post a Comment