-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathOffice365_Credentials_Tester.ps1
51 lines (46 loc) · 1.91 KB
/
Office365_Credentials_Tester.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Needed variables:
############################################################################
$path = Split-Path -parent $PSCommandPath
$list = ''
if (Get-Content $path\credentials.txt){
Write-Host "Credentials.txt was found, we can continue."
Write-Host "##################### Step 1. ####################" -BackgroundColor DarkGreen
Write-Host "############# Office 365 Validation ##############" -BackgroundColor DarkGreen
foreach($line in Get-Content $path\credentials.txt) {
if($line){
$UserName = ($line -split ':')[0]
$Password = ($line -split ':')[-1]
$securedpass = $Password | ConvertTo-SecureString -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PsCredential($UserName,$securedpass)
try{
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Cred -Authentication Basic -AllowRedirection -ErrorAction Ignore
if ($Session){
Write-Host "Valid Credentials For" $UserName -BackgroundColor Blue
Remove-PSSession $Session
$list = $UserName + " (Office 365)" + ", " + $list
}
else{
throw
}
}
catch{
Write-Host "Invalid Credentials For" $UserName -BackgroundColor Red
continue
}
}
else {
Write-Host "The file is empty, please add data - username:password."
}
}
if ($list){
Write-Host " "
Write-Host "These are the credential that were valid:"
Write-Host $list
}
else {
Write-Host "No valid credentials have been found."
}
}
else{
Write-Host "Credentials.txt wasn't found. Verify and exists and run the script again"
}