Hello,
I have the following code:
# Get all users created today and give them random passwords
$Global:Date = Get-Date -Format d
function RandomPassword {
$Global:Password = new-password -length 8 -upperCase -lowerCase -numbers
}
Import-Csv "C:\Powershell\CSV\SchoolsList.csv" | ForEach-Object {
$School = $_.School
$ou = 'OU=foo2,OU=' + $School + ',OU=foo1,DC=foo,DC=CO,DC=UK'
$Users = Get-QADUser -Title "student","parent" `
-SearchRoot $ou `
-SizeLimit 0 `
-includedproperties whenCreated
foreach ($User in $Users){$Create = $User.WhenCreated.ToShortDateString
if ($Create -eq $Date){
RandomPassword
Set-QADUser $User -UserPassword $Password -PasswordNeverExpires $False -UserMustChangePassword $true |
Select-Object title,@{n='OU';e={ $ou }}, @{n='User';e={ $User }}, @{n='Password';e={ $Password }}|
Out-File "C:\Scripts\Passwords.txt"}}}
Basically it all works apart from for some reason it will not export the information out... It created the file however nothing is ever in it I know there are two users created today and I am using this on the test network.
Does anyone know why the info is not exporting out?
Many Thanks
James