New to PW - Access Denied

Welcome Forums General PowerShell Q&A New to PW - Access Denied

This topic contains 6 replies, has 3 voices, and was last updated by

 
Participant
1 year, 4 months ago.

  • Author
    Posts
  • #72428

    Participant
    Points: 0
    Rank: Member

    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

  • #72434

    Keymaster
    Points: 1
    Rank: Member

    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.

  • #72479

    Participant
    Points: 0
    Rank: Member

    Thanks Don,

    I will try again, just bit confused why the other scripts I have run on C;\ have worked fine. Will send an update in a bit.

    I will look at that resource as well.

  • #72484

    Participant
    Points: 0
    Rank: Member

    Still not working, But my other scripts work when pointing to C:\ for example this works.

    Import-Module activedirectory

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

    forEach ($item in $list) {

    $samAccountName = $item.samAccountName

    Disable-ADAccount -Identity $samAccountName
    }

    • #72485

      Participant
      Points: 0
      Rank: Member

      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.

  • #72487

    Participant
    Points: 0
    Rank: Member

    Thanks I shall have a look. If i move to the desktop what command would i use to point to it in PS.

    sl Desktop

  • #72491

    Participant
    Points: 0
    Rank: Member

    Very odd, I decided to re create the excel file and it's worked.

    thanks all

The topic ‘New to PW - Access Denied’ is closed to new replies.