0

How can i combine below 3 powershell scripts into one single script?

  1. Delete user
  2. Hide from email address enable in exchange
  3. ActiveSync disable
  4. Export the result in csv

.

Get-content C:\TEMP\Users1.txt |get-aduser |set-aduser -enabled $false
Get-content C:\TEMP\user1.txt | Set-Mailbox -HiddenFromAddressListsEnabled $true
Get-content C:\temp\users1.txt | set-CASMailbox -ActiveSyncEnabled:$False
Export-Csv "DisableU-$(Get-Date -f yyyyMMdd_HHmm).csv" -NoType

Kindly guide me. Thanks in advance.

1 Answer 1

1

Just put them into any *.ps1 file and run from console by providing the full path to the script. If you are in the script directory just run:

./Script.ps1

You might also need to set proper Execution Policy. This is the separated topic but just for now you can set it to unrestricted.

PS> Set-ExecutionPolicy Unrestricted -Force

But please read about Execution Policies.

Sign up to request clarification or add additional context in comments.

5 Comments

is this how the code will be? Sorry im new for powershell Set-ExecutionPolicy Unrestricted -Force Get-content C:\TEMP\Users1.txt |get-aduser |set-aduser -enabled $false Get-content C:\TEMP\user1.txt | Set-Mailbox -HiddenFromAddressListsEnabled $true Get-content C:\temp\users1.txt | set-CASMailbox -ActiveSyncEnabled:$False Export-Csv "DisableU-$(Get-Date -f yyyyMMdd_HHmm).csv" -NoType
Put your code (those four lines from your question) inside Script.ps1 file, then set execution policy and after that run the file as I shown.
HI gabr, The script run if i use disable.ps1 but there is no csv file created. got error as below. cmdlet Export-Csv at command pipeline position 1 Supply values for the following parameters: InputObject: Any idea?
You're not telling Export-Csv what you want it to export. Are you trying to make a log file?
Hi Nate, Yes im trying to make log file as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.