test

3 Spice ups

Hi there,

I fully recommend separate your CSV file with comma or another character, then:

PS C:\> $users = Import-Csv -Delimiter "," -Path .\users.csv
PS C:\> ForEach ($user in $users) { if ($user.employeetype -eq 'External') { Write-Host "Put your command into this brackets for the user ---> " $user.samaccountname }}

This works fine on my desktop.

1 Spice up

And, if you want it into one command:

PS C:\> Import-Csv -Delimiter "," -Path .\users.csv | ForEach-Object { if ($_.employeetype -eq 'External') { Write-Host "put your command into this brackets for the user --> " $_.samaccountname }}
1 Spice up

great , let me give a try on sample file and will let you know :slight_smile:

thanks for the answer i tested script with minor changes and it worked fine

Import-Csv ‘C:\Users\myaccount\Desktop\contractor.csv’ | ForEach-Object { if ($.employeetype -eq ‘External’) { Set-ADUser -Identity $.sAMAccountname -AccountExpirationDate $([datetime]$_.EndDate)}}

One quick question do you know why account is extending 1 day less like in csv if expiration date is 09/30/2020 post script complete expiration date set to 09/29/2020 . any idea how i can add +1 day ?

Hi there,

Nope, that’s strange to mee too o.O…