Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

taking a power shell cmdlet and changing it into script by importing from file and applying to each name

$
0
0

In my other post I was helped out on using the command pwdlastset

https://social.technet.microsoft.com/Forums/windowsserver/en-US/ac4d4fb8-0780-4f0d-9e0e-9fec2ff87fbf/using-the-pwdlastset-attribute?forum=winserverpowershell

I decided I would then try to build on that. 

1. create a CSV file and import

2. take each value as it comes in and change it.

I came up with the following but something odd is happening:

its asking for an identity. (I got the idea from another script that I had which creates accounts, see below) any idea what I is wrong in my thinking here?

--------------------------

PS C:\Windows\system32> # Import from CSV
Import-csv c:\scripts\Book1.csv | Foreach-Object { Set-ADUser -Replace @{pwdLastSet=0}}
cmdlet Set-ADUser at command pipeline position 1
Supply values for the following parameters:
Identity:

--------------------------

I got the idea from another script that I had which creates user accounts.  it was similar type of item using the new_ADUser instead of the set-ADuser but the important thing I wanted was to create a for loop but was not sure how in power shell and this seemed to use that.

-----------------------------

# Import from CSV
Import-csv c:\scripts\PSBulkAccountCreation.csv | ForEach-Object {
              
                New-ADUser -Path "OU=users,DC=somename" -Name $_.Name -SamAccountName $_.SamAccountName -Description $_.Description -emailaddress $_.emailaddress -AccountPassword (ConvertTo-Securestring -AsplainText $_.AccountPassword -Force) -Enable $true -ChangePasswordatlogon 0 -PasswordNeverExpires:$true

}

}

-----------------------------


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>