test<\/p>","upvoteCount":3,"answerCount":6,"datePublished":"2020-06-18T12:30:39.000Z","author":{"@type":"Person","name":"spiceuser-dk5ee","url":"https://community.spiceworks.com/u/spiceuser-dk5ee"},"acceptedAnswer":{"@type":"Answer","text":"
And, if you want it into one command:<\/p>\n
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 }}\n<\/code><\/pre>","upvoteCount":1,"datePublished":"2020-06-18T12:56:00.000Z","url":"https://community.spiceworks.com/t/powershell-script/766525/3","author":{"@type":"Person","name":"linkzeta","url":"https://community.spiceworks.com/u/linkzeta"}},"suggestedAnswer":[{"@type":"Answer","text":"
Advertisement
test<\/p>","upvoteCount":3,"datePublished":"2020-06-18T12:30:40.000Z","url":"https://community.spiceworks.com/t/powershell-script/766525/1","author":{"@type":"Person","name":"spiceuser-dk5ee","url":"https://community.spiceworks.com/u/spiceuser-dk5ee"}},{"@type":"Answer","text":"
Hi there,<\/p>\n
I fully recommend separate your CSV file with comma or another character, then:<\/p>\n
PS C:\\> $users = Import-Csv -Delimiter \",\" -Path .\\users.csv\nPS C:\\> ForEach ($user in $users) { if ($user.employeetype -eq 'External') { Write-Host \"Put your command into this brackets for the user ---> \" $user.samaccountname }}\n<\/code><\/pre>\nThis works fine on my desktop.<\/p>","upvoteCount":1,"datePublished":"2020-06-18T12:52:54.000Z","url":"https://community.spiceworks.com/t/powershell-script/766525/2","author":{"@type":"Person","name":"linkzeta","url":"https://community.spiceworks.com/u/linkzeta"}},{"@type":"Answer","text":"
great , let me give a try on sample file and will let you know
<\/p>","upvoteCount":0,"datePublished":"2020-06-18T13:00:42.000Z","url":"https://community.spiceworks.com/t/powershell-script/766525/4","author":{"@type":"Person","name":"spiceuser-dk5ee","url":"https://community.spiceworks.com/u/spiceuser-dk5ee"}},{"@type":"Answer","text":"
thanks for the answer i tested script with minor changes and it worked fine<\/p>\n
Import-Csv ‘C:\\Users\\myaccount\\Desktop\\contractor.csv’ | ForEach-Object { if ($.employeetype -eq ‘External’) { Set-ADUser -Identity $<\/em>.sAMAccountname -AccountExpirationDate $([datetime]$_.EndDate)}}<\/p>\nOne 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 ?<\/p>","upvoteCount":0,"datePublished":"2020-06-18T14:00:40.000Z","url":"https://community.spiceworks.com/t/powershell-script/766525/5","author":{"@type":"Person","name":"spiceuser-dk5ee","url":"https://community.spiceworks.com/u/spiceuser-dk5ee"}},{"@type":"Answer","text":"
Hi there,<\/p>\n
Nope, that’s strange to mee too o.O…<\/p>","upvoteCount":0,"datePublished":"2020-06-19T05:36:20.000Z","url":"https://community.spiceworks.com/t/powershell-script/766525/6","author":{"@type":"Person","name":"linkzeta","url":"https://community.spiceworks.com/u/linkzeta"}}]}}