Hi,
I am trying to disable few users on AD with the help of a simple PowerShell script as below.
Import-Module ActiveDirectory
Read content from DisableUser.csv file
$users=Import-CSV C:\ADUSERS\DisableUsers.csv
ForEach ($user in $users)
{
Disable-ADAccount -Identity $($user.name)
}
When I run the above script from my laptop through PowerShell console it works fine and disables the AD accounts but the script does not run
through the Task Scheduler. In the Scheduler I found that the Task starts and finishes but the script does not run.
I even added the command below to check it the script runs but no luck.
Set-Content -Path "C:\ADUSERS\TestTaskSch.txt" -Value "Hello World"
The Task Scheduler settings are given below.
Program/Script: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Argument : -File "C:\PSScripts\DisableADUsers.ps1" ( file location of the script)
Kindly help.
Cheers
Pankaj