Disable AD accounts from CSV with custom output

Welcome Forums General PowerShell Q&A Disable AD accounts from CSV with custom output

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

11 months, 2 weeks ago.

  • Author
  • #95483

    Points: 1
    Rank: Member


    I have a CSV file having email address of multiple users in column A. I need output as below:

    Get ONLY the SamAccountName from those email IDs and export it to column B of same CSV.
    Disable all the listed users.
    After disabling the account, add a comment column (column C) in same CSV with the status "successful" or "unsuccessful".

  • #95484

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    So it's not actually possible to "update an existing CSV;" what you can do is either overwrite the original, or write a new one with the additional data.

    You'd obviously use Import-CSV to read in the source CSV.

    You'd enumerate those rows in a ForEach.

    For each row, you'd parse the data down to whatever you wanted, disable the user, and then output a custom object. Each property in the object would represent a new column-to-be in your new CSV file. I cover this pretty extensively in "Learn PowerShell Scripting in a Month of Lunches," FWIW.

    That object would be piped to Export-CSV to create the new CSV.

  • #95487

    Points: 723
    Helping Hand
    Rank: Major Contributor


    sound's a little bit like you're requesting a customized script solution from us. This is a peer to peer forum. If you have problems with some Powershell code you wrote we are happy to try to help you with it but we will not write ready to use code for you. You are expected to do that by yourself.

    • #95492

      Points: 1
      Rank: Member

      Olaf, yes it's sound like a request for a code. I am completely unaware of Powershell or Scripting/Programming. Tried to learn through online courses but still too confused in the PS syntax. Specially while writing code. Anyhow, I think I have to work even more harder. However if you can suggest any website/video/docs, which can help me to learn Powershell in easiest way, I will be thankful.

The topic ‘Disable AD accounts from CSV with custom output’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort