?
Solved

PowerShell Import-Module

Posted on 2015-01-20
4
Medium Priority
?
100 Views
Last Modified: 2015-01-20
Hello,

From my Windows 7 Professional SP1 desktop OS I've upgraded to PowerShell 3.0. I'd like to make AD calls to report on the AD objects.

What needs to occur to allow the import-module function to work?
For example; import-module activedirectory

import-module activedirectory  
#Create a variable for the date stamp in the log file
$LogDate = get-date -f yyyyMMddhhmm

#Sets the OU to do the base search for all user accounts, change for your env.
$SearchBase = "CN=Temp Associates,OU=Res Accounts,DC=our,DC=domain,DC=org"

#Create an empty array for the log file
$LogArray = @()

#Sets the number of days to disable user accounts based on lastlogontimestamp and pwdlastset.
$PasswordAge = (Get-Date).adddays(-29)

#Use ForEach to loop through all users with pwdlastset and lastlogontimestamp greater than date set. Also added users with no lastlogon date set. Disables the accounts and adds to log array.
#Add the properties you will be using to ensure they are available.
$DisabledUsers = (Get-ADUser -searchbase $SearchBase -Properties samaccountname, name, distinguishedname -filter {((lastlogondate -notlike "*") -OR (lastlogondate -le $Passwordage)) -AND (enabled -eq $True) -AND (whencreated -le $Passwordage)} )
0
Comment
Question by:CuriousMAUser
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 70

Expert Comment

by:Qlemo
ID: 40559806
Starting with PS 3 you do no longer need to explicitely import modules, though it is a good idea to do so. PS 3 will otherwise try to find the corresponding module in the default location automatically. The default locations are set in $env:PSModulPath. The same path is used if you import modules by just naming them (versus providing a complete path).

If you had the AD cmdlets work prior to updating PS,  they should still work.
0
 

Author Comment

by:CuriousMAUser
ID: 40559833
Why should a person create a PowerShell Function and what is the benefit?

What are relevant examples of AD function calls?

Thank you.
0
 
LVL 70

Accepted Solution

by:
Qlemo earned 2000 total points
ID: 40559846
What is the relation to this question? Both questions are loosely connected only.
0
 

Author Closing Comment

by:CuriousMAUser
ID: 40560062
Thank you.
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question