Author Posts

March 8, 2018 at 10:48 pm

Friends,

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".

March 8, 2018 at 10:57 pm

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.

March 8, 2018 at 11:00 pm

Nilabh,

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.

March 8, 2018 at 11:14 pm

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.