connectionscript.ps1


<#PSScriptInfo
 
.VERSION 1.0
 
.GUID 8e1cb770-55b4-457d-8de2-fad77ee32439
 
.AUTHOR Chris.Loonan
 
.COMPANYNAME
 
.COPYRIGHT
 
.TAGS
 
.LICENSEURI
 
.PROJECTURI
 
.ICONURI
 
.EXTERNALMODULEDEPENDENCIES
 
.REQUIREDSCRIPTS
 
.EXTERNALSCRIPTDEPENDENCIES
 
.RELEASENOTES
 
 
#>


<#
 
.DESCRIPTION
 Sharepoin
 
#>
 

#Param()




Function Warning {
clear-host
Write-Warning "`n `n Just a heads up... This Script is meant to login to the services you want, some services require additional password prompts due to Modern Authentication `n `n Additionally you may need to download modules for certain cervices. Auto download is currently being developed. " -WarningAction Inquire
}
Warning
Function Credentials ($userCredentials) {
$global:userCredentials=Get-Credential
    <#$I = 0
    for(){
        try{
            if($i -ne -0){
                Write-Host -NoNewLine 'Invalid Credentials or Credential Timeout...'
                $null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
                }
                $userCredentials = Get-Credential
         
            }
            catch [System.Management.Automation.Remoting.PSRemotingTransportException],[System.Management.Automation.ParameterBindingException]{
                if($i -eq 2){
                    return
                    }
                }
                $i = $i + 1
        }#>

    }
Credentials




function GenerateForm {

[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null

$form1 = New-Object System.Windows.Forms.Form
$button1 = New-Object System.Windows.Forms.Button
$listBox1 = New-Object System.Windows.Forms.ListBox
$checkBox5 = New-Object System.Windows.Forms.CheckBox
$checkBox4 = New-Object System.Windows.Forms.CheckBox
$checkBox3 = New-Object System.Windows.Forms.CheckBox
$checkBox2 = New-Object System.Windows.Forms.CheckBox
$checkBox1 = New-Object System.Windows.Forms.CheckBox
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState

$b1= $false
$b2= $false
$b3= $false

#----------------------------------------------
#Generated Event Script Blocks
#----------------------------------------------

$handler_button1_Click= 
{
    $listBox1.Items.Clear();    

    if ($checkBox1.Checked)     {  $listBox1.Items.Add( "Exchange Login Started"  ) 
        $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell-liveid/ -Credential $userCredentials -Authentication Basic -AllowRedirection  -ErrorAction  Stop
        Import-PSSession $Session -allowclobber
        
    }
    
    
    if ($checkBox2.Checked)    {  $listBox1.Items.Add( "Connecting to MSOnline"  ) 
        Connect-Msolservice -credential $userCredentials
        }
    if ($checkBox3.Checked)    {  $listBox1.Items.Add( "Connecting to security and Compliance"  ) 
    
        Import-Module $((Get-ChildItem -Path $($env:LOCALAPPDATA + "\Apps\2.0\") -Filter Microsoft.Exchange.Management.ExoPowershellModule.dll -Recurse).FullName | ?{ $_ -notmatch "_none_" } | select -First 1)
        $UPN=$userCredentials.getNetworkCredential().username
        $MFCCPSSession = New-ExoPSSession -ConnectionUri 'https://ps.compliance.protection.outlook.com/PowerShell-LiveId' -userprincipalname $UPN
        Import-PSSession $MFCCPSSession -AllowClobber
        }
    
    if ($checkBox4.Checked)    {  $listBox1.Items.Add( "Skype For Businessness"  ) 
        $domainGrab=Read-Host "What is your .onmicrosoft domain? (will auto populate soon)"
        <#
        Connect-Msolservice -credential $userCredentials
        $domainGrab = Get-MsolDomain | where-object {$_.name -like "
        *.onmicrosoft.com" -and $_.name -notlike "*.mail.onmicrosoft.com"} | Select-Object name
#>

        $cssession = New-CsOnlineSession -Credential $userCredentials -OverrideAdminDomain $domainGrab 
        Import-PSSession $cssession
        }
        
    if ($checkbox5.Checked)       { $listbox1.Items.Add( "Connecting to Sharepoint Online") 

        
    kill -processname msiexec -erroraction silentlycontinue
    $installPath ="$env:USERPROFILE\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\SharePoint Online Management Shell"
    $downloadPath = "$($env:USERPROFILE)\Downloads\share*.msi"
    $downloadTruther= Test-Path $downloadPath
    $installTruther = Test-path $installPath
    $procTruther = Get-Process msiexec -erroraction Silentlycontinue


    #if download is true or msiexec running is true
    #msiexec
    if($installTruther -eq $false){
        if($downloadTruther -eq $false){    
                    
            Write-Host "`n Redirecting to module Download ."
            $IE=new-object -com internetexplorer.application
            $IE.navigate2("https://www.microsoft.com/en-us/download/confirmation.aspx?id=35588")
            $IE.visible=$true
            do{
                $downloadTruther= Test-Path $downloadPath
                $procTruther = Get-Process msiexec -erroraction Silentlycontinue
                Write-Host "`n Waiting..."
                Start-Sleep -seconds 3
            }
            while($downloadTruther -ne $true -and $procTruther -eq $null)
            
        }
        #this is broken
        #no it's not
        #well it was
        #so delete the other comment
        #no you
        invoke-item "$($env:USERPROFILE)\Downloads\share*.msi"
        do{
            $installTruther= Test-Path $installPath
            Write-Host "`n Waiting2..."
            Start-sleep -seconds 3
            }
            while($installTruther -ne $true)
            }
            

    #import-module microsoft.online.sharepoint.powershell
    #>

    import-module "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.Online.SharePoint.PowerShell.dll"
    Write-Host "Please enter Your .onmicrosoft.com EX: domain.onmicrosoft.com"
    Connect-SpoService
    
    
    ############################################
    }
    if ( !$checkBox1.Checked -and !$checkBox2.Checked -and !$checkBox3.Checked -and !$checkbox4.Checked ) {   $listBox1.Items.Add("No CheckBox selected....")} 
    $form1.Close()
}

$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
    $form1.WindowState = $InitialFormWindowState
}

#----------------------------------------------

$form1.Text = "Login Scripts"
$form1.Name = "form1"
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 450
$System_Drawing_Size.Height = 300
$form1.ClientSize = $System_Drawing_Size

$button1.TabIndex = 4
$button1.Name = "button1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 75
$System_Drawing_Size.Height = 23
$button1.Size = $System_Drawing_Size
$button1.UseVisualStyleBackColor = $True

$button1.Text = "Run Script"

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 27
$System_Drawing_Point.Y = 250
$button1.Location = $System_Drawing_Point
$button1.DataBindings.DefaultDataSourceUpdateMode = 0
$button1.add_Click($handler_button1_Click)

$form1.Controls.Add($button1)

$listBox1.FormattingEnabled = $True
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 264
$System_Drawing_Size.Height = 212
$listBox1.Size = $System_Drawing_Size
$listBox1.DataBindings.DefaultDataSourceUpdateMode = 0
$listBox1.Name = "listBox1"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 160
$System_Drawing_Point.Y = 13
$listBox1.Location = $System_Drawing_Point
$listBox1.TabIndex = 3

$form1.Controls.Add($listBox1)


$checkBox5.UseVisualStyleBackColor = $True
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 114
$System_Drawing_Size.Height = 34
$checkBox5.Size = $System_Drawing_Size
$checkBox5.TabIndex = 6
$checkBox5.Text = "Sharepoint Online"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 27
$System_Drawing_Point.Y = 200
$checkBox5.Location = $System_Drawing_Point
$checkBox5.DataBindings.DefaultDataSourceUpdateMode = 0
$checkBox5.Name = "checkBox5"

$form1.Controls.Add($checkBox5)



$checkBox4.UseVisualStyleBackColor = $True
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 104
$System_Drawing_Size.Height = 34
$checkBox4.Size = $System_Drawing_Size
$checkBox4.TabIndex = 5
$checkBox4.Text = "Skype For Business"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 27
$System_Drawing_Point.Y = 150
$checkBox4.Location = $System_Drawing_Point
$checkBox4.DataBindings.DefaultDataSourceUpdateMode = 0
$checkBox4.Name = "checkBox4"

$form1.Controls.Add($checkBox4)



$checkBox3.UseVisualStyleBackColor = $True
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 104
$System_Drawing_Size.Height = 34
$checkBox3.Size = $System_Drawing_Size
$checkBox3.TabIndex = 2
$checkBox3.Text = "Security and Compliance"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 27
$System_Drawing_Point.Y = 100
$checkBox3.Location = $System_Drawing_Point
$checkBox3.DataBindings.DefaultDataSourceUpdateMode = 0
$checkBox3.Name = "checkBox3"

$form1.Controls.Add($checkBox3)


$checkBox2.UseVisualStyleBackColor = $True
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 104
$System_Drawing_Size.Height = 34
$checkBox2.Size = $System_Drawing_Size
$checkBox2.TabIndex = 1
$checkBox2.Text = "MsOnline"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 27
$System_Drawing_Point.Y = 50
$checkBox2.Location = $System_Drawing_Point
$checkBox2.DataBindings.DefaultDataSourceUpdateMode = 0
$checkBox2.Name = "checkBox2"

$form1.Controls.Add($checkBox2)



$checkBox1.UseVisualStyleBackColor = $True
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 104
$System_Drawing_Size.Height = 34
$checkBox1.Size = $System_Drawing_Size
$checkBox1.TabIndex = 0
$checkBox1.Text = "Exchange"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 27
$System_Drawing_Point.Y = 10
$checkBox1.Location = $System_Drawing_Point
$checkBox1.DataBindings.DefaultDataSourceUpdateMode = 0
$checkBox1.Name = "checkBox1"

$form1.Controls.Add($checkBox1)


#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$form1.ShowDialog()| Out-Null

} #End Function

#Call the Function
GenerateForm






#https://www.microsoft.com/en-us/download/confirmation.aspx?id=39366
#Set-SPOSite -Identity https://contoso.sharepoint.com/sites/site1 -SharingCapability ExternalUserAndGuestSharing