locked
New to PS - Access Denied RRS feed

  • Question

  • 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
    + $list = Import-CSV c:\passwordneverexpires.csv
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : OpenError: (:) [Import-Csv], UnauthorizedAccessException
    + FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.ImportCsvCommand

    HOWEVER - other scripts/commands work, for example - 

    Import-Module activedirectory

    $list = Import-CSV c:\disableusers.csv

    forEach ($item in $list) {

    $samAccountName = $item.samAccountName

    Disable-ADAccount -Identity $samAccountName
    }

    Friday, June 9, 2017 9:32 AM

Answers

  • Hi,

    seems you don't have rights to read this special csv file. Can you open it manually in explorer?

    Best regards

    Christoph

    • Marked as answer by TheHunter85 Friday, June 9, 2017 11:10 AM
    Friday, June 9, 2017 10:18 AM

All replies

  • Hi,

    seems you don't have rights to read this special csv file. Can you open it manually in explorer?

    Best regards

    Christoph

    • Marked as answer by TheHunter85 Friday, June 9, 2017 11:10 AM
    Friday, June 9, 2017 10:18 AM
  • Hi Christoph 

    I made the file myself and can open and edit it in explorer, I will create a new one again. It is just really strange.

    Any other suggestions?  

    Friday, June 9, 2017 11:05 AM
  • ok that is odd, i recreated the excel and all is working ... thanks 
    Friday, June 9, 2017 11:10 AM
  • It is likely that the old file was open in Excel.


    \_(ツ)_/

    Friday, June 9, 2017 5:46 PM