Disable AD accounts from CSV with custom output

This topic contains 3 replies, has 3 voices, and was last updated by  Nilabh Verma 2 months, 2 weeks ago.

  • Author
  • #95483

    Nilabh Verma


    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

    Don Jones

    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

    Olaf Soyk


    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

      Nilabh Verma

      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.

You must be logged in to reply to this topic.