Jump to content

Hi members, 

 

I need help with making a powershell script that will be used within my work's domain and target only USERS not administrators.  Specifically targeting account expiration dates.  Now I'm tasked with having to make a script but I don't know jack about scripting or powershell.  I did a basic google search this is what I found: 

Param (
[Parameter(Mandatory=$True,ValueFromPipeline=$true)]
[Array]$Usernames,
[Parameter(Mandatory=$True)]
[datetime]$Expires = $(Read-Host -Prompt "Please enter the time to expire in format [06/01/2017 00:00:00 AM]")
)
begin
{ ### Attempts to Import ActiveDirectory Module. Produces error if fails.
Try { Import-Module ActiveDirectory -ErrorAction Stop }
Catch { Write-Host "Unable to load Active Directory module, is RSAT installed?"; Break }
}
Process
{ #This command takes the previous 2 inputs and executes the command.
ForEach ($Username in $example.local\$examples\$sites\)
{ Set-ADUser $Username -AccountExpirationDate $Expires
}
}

 

I did some editing of it but I was told that it was too long and could be simplified.  I need help.

Thanks in advance.

Link to comment
https://linustechtips.com/topic/603863-powershell-script-help/
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×