Hi all, literally my first day dipping in to PowerSHell. I have done ok so far, but i have hit a hurdle. In short I am currently trying to set all AD users account passwords to be set to expire in 90 days. I have been using this script however I keep getting access denied.
Other scripts have worked fine that are in the c:\ location. I am using Domain admin.
PS C:\WINDOWS> Import-Module activedirectory
$list = Import-CSV c:\passwordneverexpires.csv
forEach ($item in $list) {
$samAccountName = $item.samAccountName
Disable-ADAccount -Identity $samAccountName
}
Import-CSV : Access to the path ‘C:\passwordneverexpires.csv’ is denied.
At line:3 char:9
Welcome! I hope you’re considering “Learn Windows PowerShell in a Month of Lunches” as a resource.
The error is telling you that whatever user account you’re using to run the PowerShell console doesn’t have access to that file. I suspect you’re not running the shell as Administrator, since users by default don’t have access to C: on newer systems.
Have you looked at the permissions on the file? One thing I’ve done before when testing something over and over is leave the file open. I think the error message is different, like “path not found” but still make sure it’s closed, make sure you have permissions by looking at the permissions tab and try moving it to your desktop or something. By the way, the Month of Lunches book is totally worth it.