#requires -version 3.0 Function Set-OWALogon { [cmdletbinding()] Param( [Parameter(Position=0,Mandatory=$True,ValueFromPipelineByPropertyName=$True, ValueFromPipeline=$True)] [ValidateNotNullorEmpty()] [alias("name")] [string]$Mail, [Parameter(Position=1,Mandatory=$True)] [ValidateNotNullorEmpty()] [string]$Password, [ValidateNotNullorEmpty()] [string]$Uri = "http://chi-ex01.globomantics.local/owa" ) Process { $username = $mail Write-Verbose "Invoke web request OWA logon via $uri for $username" $r = Invoke-WebRequest $uri -SessionVariable owa $form = $r.Forms[0] $Form.fields.username= $username $form.Fields.password= $password $authpath = "$uri/auth/owaauth.dll" $r = Invoke-WebRequest -Uri $authpath -WebSession $owa -Method POST -Body $form.Fields Write-Verbose $r.StatusDescription #fill out language form if ($r.forms[0].id -eq "lngfrm") { Write-verbose "First time logon" $form = $r.Forms[0] #add fields to the form using the default values $form.Fields.add("lcid",$r.ParsedHtml.getElementById("selLng").value) $form.Fields.add("tzid",$r.ParsedHtml.getElementById("selTZ").value) $langpath = "$uri/lang.owa" $r = Invoke-WebRequest -Uri $langpath -WebSession $owa -Method $form.Method -Body $form.fields write-verbose $r.Statusdescription } #if elseif ($r.forms[0].id -eq "logonform") { #we got the logon form again so something went wrong Write-Warning "Failed to logon $username. Check the password or account." } } #process } #end function $OUPath = "OU=Employees,DC=globomantics,DC=local" $users = get-aduser -filter {mail -like "*" -AND enabled -eq $True} -properties mail -SearchBase $OUPath -ErrorAction Stop #get a random number of users $randomusers = $users | get-random -count 25 foreach ($user in $randomusers) { write-host "$(Get-Date) Logging on $($user.mail)" -fore Green Set-OWALogon $user.mail "P@ssw0rd" Start-sleep -Seconds (Get-random -min 5 -max 30) }