Exchange.Connection.Manager.psm1
function Start-ECM { Connect-Exchange } function Connect-Exchange { <# .SYNOPSIS Connect to Exchange using a predefined connection. .DESCRIPTION Creates and imports a new PSSession. .EXAMPLE Choose your Connection from the connection menu. Connect-Exchange .EXAMPLE Start a connection skipping connection menu. Connect-Exchange -Identity 'PROD' .Example Choose your Connection from the simple connection menu. Connect-Exchange -SimpleMenu #> [CmdletBinding()] param ( # Parameter description [Parameter(Mandatory = $false)] [string] $Identity, [ValidateSet('Exchange','SCC','EOP')] [string] $ConnectionType, [Parameter(Mandatory = $false)] [switch] $SimpleMenu ) if ((Test-Path ($pspp + 'ECM.config')) -eq $false ) { Write-Error -Message 'Connection file not found. Use New-ECMConnection to create a new connection.' return } $host.ui.RawUI.WindowTitle = '(c)atwork deutschland GmbH - Exchange Connection Manager' if ($host.name -like '*ISE*') { $SimpleMenu = $true } Function Show-Menu { param ($menuItems, $menuPosition, $menuTitel) $fcolor = $host.UI.RawUI.ForegroundColor $bcolor = $host.UI.RawUI.BackgroundColor $l = $menuItems.length + 1 $menuwidth = $menuTitel.length + 4 Clear-Host Write-Host -Object "`t" -NoNewline Write-Host -Object ('*' * $menuwidth) -ForegroundColor $fcolor -BackgroundColor $bcolor Write-Host -Object "`t" -NoNewline Write-Host -Object "* $menuTitel *" -ForegroundColor $fcolor -BackgroundColor $bcolor Write-Host -Object "`t" -NoNewline Write-Host -Object ('*' * $menuwidth) -ForegroundColor $fcolor -BackgroundColor $bcolor Write-Host -Object '' Write-Debug -Message "L: $l MenuItems: $menuItems MenuPosition: $menuPosition" for ($i = 0; $i -le $l;$i++) { Write-Host -Object "`t" -NoNewline if ($i -eq $menuPosition) { Write-Host -Object "$($menuItems[$i])" -ForegroundColor $bcolor -BackgroundColor $fcolor } else { Write-Host -Object "$($menuItems[$i])" -ForegroundColor $fcolor -BackgroundColor $bcolor } } } Function Get-Menu { param ([array]$menuItems, $menuTitel = 'MENU') $vkeycode = 0 $pos = 0 Show-Menu $menuItems $pos $menuTitel While ($vkeycode -ne 13) { $press = $host.ui.rawui.readkey('NoEcho,IncludeKeyDown') $vkeycode = $press.virtualkeycode Write-Host -Object "$($press.character)" -NoNewline If ($vkeycode -eq 38) { $pos-- } If ($vkeycode -eq 40) { $pos++ } if ($pos -lt 0) { $pos = 0 } if ($pos -ge $menuItems.length) { $pos = $menuItems.length -1 } Show-Menu $menuItems $pos $menuTitel } Write-Output -InputObject $($menuItems[$pos]) } Function Start-Menue { param ( [Object] $MenueOptions ) $MenueSelection = Get-Menu $MenueOptions 'Choose your Exchange Connection' return $MenueSelection } function Disconnect-Connection { param( [string] $ConnectionName, [string] $Prefix ) $ConnectionDB = Import-Clixml ($pspp + 'ECM.config') $PSSessions = Get-PSSession |Select-Object -Property Name, State foreach ($PSSession in $PSSessions) { if ($PSSession.State -ne 'Opened' -and $ConnectionName -eq $PSSession.Name) { Write-Warning -Message ('Removing existing Connection: ' + $PSSession.Name) Get-PSSession -Name $PSSession.Name |Remove-PSSession $host.ui.RawUI.WindowTitle = $null } if ($PSSession.State -eq 'Opened' -and $ConnectionName -eq $PSSession.Name) { Write-Warning -Message ('Session already active: ' + $PSSession.Name) return $false } if ($ConnectionName -ne $PSSession.Name) { #Get Session Prefix $SessionPrefix = $ConnectionDB |Where-Object -FilterScript { $_.Identity -eq $PSSession.Name } if ($SessionPrefix.Prefix -eq $Prefix -or ($SessionPrefix.Prefix -eq $null -and $Prefix -eq $null) -or ($SessionPrefix.Prefix -like '' -and $Prefix -like '') ) { Write-Warning -Message ('Connection ' + $ConnectionName + ' uses the same Prefix as Connection ' + $PSSession.Name) Write-Warning -Message ('Removing existing Connection: ' + $PSSession.Name) Get-PSSession -Name $PSSession.Name |Remove-PSSession $host.ui.RawUI.WindowTitle = $null } } } return $true } function Start-ExchangeConnection { param ( [Object] $Connection, [ValidateSet('Exchange','SCC','EOP')] [string] $ConnectionType ) if ($ConnectionType -eq 'Exchange') { $URI = $Connection.URI $Identity = $Connection.Identity } if ($ConnectionType -eq 'SCC') { $URI = $Connection.SCCURI $Identity = ('SCC:' + $Connection.Identity) } if ($ConnectionType -eq 'EOP') { $URI = $Connection.EOPURI $Identity = ('EOP:' + $Connection.Identity) } $stat = Disconnect-Connection -ConnectionName $Identity -Prefix $Connection.Prefix $host.ui.RawUI.WindowTitle = 'ECM | ' + $Identity $cred = New-Object -TypeName System.Management.Automation.PSCredential ` -ArgumentList $Connection.UserName, ($Connection.Password| ConvertTo-SecureString) if ($stat -eq $true) { $ExchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $URI -Credential $cred -Authentication $Connection.Authentication -AllowRedirection -Name $Identity if ($ExchangeSession -eq $null) { Write-Error ('Unable to connect to Session ' + $Connection.Identity + ' ' + $URI) return } if ($Connection.Prefix -ne $null -and $Connection.Prefix -notlike '') { Import-Module (Import-PSSession -Session $ExchangeSession -AllowClobber -DisableNameChecking) -Global -DisableNameChecking -Prefix $Connection.prefix } else { Import-Module (Import-PSSession -Session $ExchangeSession -AllowClobber -DisableNameChecking) -Global -DisableNameChecking } if ($Connection.UnlimitedEnumeration -eq $true) { $global:FormatEnumerationLimit = -1 } } } function Start-FullMenueMode { $ScriptMenueItems = @() foreach ($element in $ConnectionDB) { $ScriptMenueItems += $element.Identity if($element.SCCHidden -eq $false -and $element.Type -eq 'Online') { $ScriptMenueItems += 'SCC:' + $element.Identity } if($element.EOPHidden -eq $false -and $element.Type -eq 'Online') { $ScriptMenueItems += 'EOP:' + $element.Identity } } $choice = Start-Menue $ScriptMenueItems if ($choice -like 'SCC:*') { $choice = $choice -replace 'SCC:' $Connect = $ConnectionDB |Where-Object -FilterScript { $_.Identity -eq $choice } Start-ExchangeConnection -Connection $Connect -ConnectionType SCC return } if ($choice -like 'EOP:*') { $choice = $choice -replace 'EOP:' $Connect = $ConnectionDB |Where-Object -FilterScript { $_.Identity -eq $choice } Start-ExchangeConnection -Connection $Connect -ConnectionType EOP return } $Connect = $ConnectionDB |Where-Object -FilterScript { $_.Identity -eq $choice } Start-ExchangeConnection -Connection $Connect -ConnectionType Exchange } function Start-SimpleMenuMode { $i = 1 foreach ($item in $ConnectionDB) { Write-Host -Object ('[' + $i + '] ' + $item.Identity) $i++ } $choice = Read-Host -Prompt 'Choose Connection Number' if ($choice -gt $i) { Write-Error -Message 'Connection Number invalid.' return } $Connect = $ConnectionDB[($choice -1)] Start-ExchangeConnection -Connection $Connect -ConnectionType Exchange } try { if ((Test-Path -Path ($pspp + 'ECM.config')) -ne $false) { $ConnectionDB = Import-Clixml ($pspp + 'ECM.config') if ($Identity -ne $null -and $Identity -notlike '') { $Connect = $ConnectionDB |Where-Object -FilterScript { $_.Identity -eq $Identity } if ($Connect -eq $null) { Write-Error -Message 'Connection Name (' $Identity ') not found.' return } if ($ConnectionType -eq $null -or $ConnectionType -like '' -or $ConnectionType -eq 'Exchange') { Start-ExchangeConnection -Connection $Connect -ConnectionType Exchange } if ($ConnectionType -eq 'SCC') { Start-ExchangeConnection -Connection $Connect -ConnectionType SCC } if ($ConnectionType -eq 'EOP') { Start-ExchangeConnection -Connection $Connect -ConnectionType EOP } } else { if ($SimpleMenu -eq $true) { Start-SimpleMenuMode } else { Start-FullMenueMode } } } else { Write-Error -Message 'Connection Database not found. ' + ($pspp + 'ECM.config') + 'Use New-ECMConnection to create a new database.' } } catch { Write-Error $_ } } function Disconnect-Exchange { param( [string] $Identity ) if ($Identity -ne $null -and $Identity -notlike '') { Get-PSSession | Where-Object -FilterScript { $_.Name -like '*' + $Identity }| ForEach-Object -Process { Remove-PSSession } } else { $sessions = Get-PSSession Get-ECMConnection |ForEach-Object -Process { foreach ($session in $sessions) { if ($session.Name -like ('*' + $_.Identity)) { Get-PSSession -Name $session.Name |Remove-PSSession } } } } } function New-ECMConnection { param( [Parameter(Mandatory = $true)] [string] $Identity, [Parameter(Mandatory = $true)] [ValidateSet('Online','OnPrem')] $Type, [string] $Prefix, [switch] $UnlimitedEnumeration ) DynamicParam{ if($Type -eq 'OnPrem') { # Set the dynamic parameters' name $ParamName_URI = 'URI' # Create the collection of attributes $AttributeCollection = New-Object -TypeName System.Collections.ObjectModel.Collection[System.Attribute] # Create and set the parameters' attributes $ParameterAttribute = New-Object -TypeName System.Management.Automation.ParameterAttribute $ParameterAttribute.Mandatory = $true $ParameterAttribute.Position = 5 # Add the attributes to the attributes collection $AttributeCollection.Add($ParameterAttribute) # Create the dictionary $RuntimeParameterDictionary = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameterDictionary # Create and return the dynamic parameter $RuntimeParameter = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameter -ArgumentList ($ParamName_URI, [string], $AttributeCollection) $RuntimeParameterDictionary.Add($ParamName_URI, $RuntimeParameter) # Set the dynamic parameters' name $ParamName_Authentication = 'Authentication' # Create the collection of attributes $AttributeCollection = New-Object -TypeName System.Collections.ObjectModel.Collection[System.Attribute] # Create and set the parameters' attributes $ParameterAttribute = New-Object -TypeName System.Management.Automation.ParameterAttribute $ParameterAttribute.Mandatory = $true $ParameterAttribute.Position = 6 # Add the attributes to the attributes collection $AttributeCollection.Add($ParameterAttribute) # Generate and set the ValidateSet $arrSet = 'Basic', 'Kerberos' $ValidateSetAttribute = New-Object -TypeName System.Management.Automation.ValidateSetAttribute -ArgumentList ($arrSet) # Add the ValidateSet to the attributes collection $AttributeCollection.Add($ValidateSetAttribute) # Create and return the dynamic parameter $RuntimeParameter = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameter -ArgumentList ($ParamName_Authentication, [string], $AttributeCollection) $RuntimeParameterDictionary.Add($ParamName_Authentication, $RuntimeParameter) return $RuntimeParameterDictionary } } Process{ function Test-ECMConnectionName { param( [string] $ConnectionName, [object] $ConnectionDatabase ) foreach ($element in $ConnectionDatabase) { if ($element.Identity -eq $ConnectionName) { return $true } } return $false } #Process Parameters if ($Type -eq 'Online') { $URI = 'https://outlook.office365.com/powershell-liveid/' $SCCURI = 'https://ps.compliance.protection.outlook.com/powershell-liveid/' $EOPURI = 'https://ps.protection.outlook.com/powershell-liveid/' } else { $URI = $RuntimeParameterDictionary.uri.value } if ($ParamName_Authentication -ne $null -or $ParamName_Authentication -notlike '') { $Authentication = $RuntimeParameterDictionary.authentication.value } else { $Authentication = 'Basic' } if ($Prefix -eq $null -or $Prefix -like '') { $Prefix = $null } #Test Connection File and PowerShell folder if ((Test-Path -Path ($pspp + 'ECM.config')) -eq $false) { if ((Test-Path -Path $pspp) -eq $false) { New-Item -Path $pspp -type Directory } } else { #Update ECM Config File $ECMConfig = Import-Clixml ($pspp + 'ECM.config') } if ((Test-ECMConnectionName -ConnectionName $Identity -ConnectionDatabase $ECMConfig) -eq $false) { $ConnectionCredentials = Get-Credential -Message ('Credentials for connection ' + $Identity) if ($ConnectionCredentials -eq $null) { Write-Error ('Credentials are mandatory. Please try again.') return } #Create Connection Object $ConnectionObject = New-Object -TypeName psobject $ConnectionObject |Add-Member -MemberType NoteProperty -Name 'Identity' -Value $Identity $ConnectionObject |Add-Member -MemberType NoteProperty -Name 'Type' -Value $Type $ConnectionObject |Add-Member -MemberType NoteProperty -Name 'URI' -Value $URI $ConnectionObject |Add-Member -MemberType NoteProperty -Name 'SCCURI' -Value $SCCURI $ConnectionObject |Add-Member -MemberType NoteProperty -Name 'SCCHidden' -Value $true $ConnectionObject |Add-Member -MemberType NoteProperty -Name 'EOPURI' -Value $EOPURI $ConnectionObject |Add-Member -MemberType NoteProperty -Name 'EOPHidden' -Value $true $ConnectionObject |Add-Member -MemberType NoteProperty -Name 'Prefix' -Value $Prefix $ConnectionObject |Add-Member -MemberType NoteProperty -Name 'Authentication' -Value $Authentication $ConnectionObject |Add-Member -MemberType NoteProperty -Name 'UnlimitedEnumeration' -Value $UnlimitedEnumeration $ConnectionObject |Add-Member -MemberType NoteProperty -Name 'UserName' -Value $ConnectionCredentials.UserName $ConnectionObject |Add-Member -MemberType NoteProperty -Name 'Password' -Value ($ConnectionCredentials.Password |ConvertFrom-SecureString) $NewECMConfig = @() if ($ECMConfig -ne $null) { $ECMConfig |ForEach-Object -Process { $obj = New-Object -TypeName psobject $obj |Add-Member -MemberType NoteProperty -Name 'Identity' -Value $_.Identity $obj |Add-Member -MemberType NoteProperty -Name 'Type' -Value $_.Type $obj |Add-Member -MemberType NoteProperty -Name 'URI' -Value $_.URI $obj |Add-Member -MemberType NoteProperty -Name 'SCCURI' -Value $_.SCCURI $obj |Add-Member -MemberType NoteProperty -Name 'SCCHidden' -Value $_.SCCHidden $obj |Add-Member -MemberType NoteProperty -Name 'EOPURI' -Value $_.EOPURI $obj |Add-Member -MemberType NoteProperty -Name 'EOPHidden' -Value $_.EOPHidden $obj |Add-Member -MemberType NoteProperty -Name 'Prefix' -Value $_.Prefix $obj |Add-Member -MemberType NoteProperty -Name 'Authentication' -Value $_.Authentication $obj |Add-Member -MemberType NoteProperty -Name 'UnlimitedEnumeration' -Value $_.UnlimitedEnumeration $obj |Add-Member -MemberType NoteProperty -Name 'UserName' -Value $_.UserName $obj |Add-Member -MemberType NoteProperty -Name 'Password' -Value $_.Password $NewECMConfig += $obj } } $NewECMConfig += $ConnectionObject $NewECMConfig |Export-Clixml ($pspp + 'ECM.config') } else { Write-Error ('A Connection with that name is already present ' + $Identity + '. Please specify another name.') return } } } function Get-ECMConnection { param( [string] $Identity ) try { if ((Test-Path ($pspp + 'ECM.config')) -eq $false ) { Write-Error -Message 'Connection file not found. Use New-ECMConnection to create a new connection.' return } $ECMConfig = Import-Clixml ($pspp + 'ECM.config') [string[]]$properties = 'Identity', 'UserName', 'Type', 'Prefix' [System.Management.Automation.PSMemberInfo[]]$PSStandardMembers = New-Object -TypeName System.Management.Automation.PSPropertySet -ArgumentList DefaultDisplayPropertySet, $properties $ECMConfig | Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $PSStandardMembers -Force if ($Identity -ne $null -and $Identity -notlike '') { return ($ECMConfig |Where-Object -FilterScript { $_.Identity -eq $Identity }) } else { return $ECMConfig } } catch { Write-Error $_ } } function Remove-ECMConnection { param( [Parameter(Mandatory = $true)] [string] $Identity, [bool] $Confirm = $true ) if ((Test-Path ($pspp + 'ECM.config')) -eq $false ) { Write-Error -Message 'Connection file not found. Use New-ECMConnection to create a new connection.' return } $ECMConfig = Import-Clixml ($pspp + 'ECM.config') $exists = $false $ECMConfig|ForEach-Object -Process { if ($Identity -eq $_.Name) { $exists = $true } } if ($exists -eq $false) { Write-Error ('Connection ' + $Identity + ' not found.') return } $ECMConfig = $ECMConfig |Where-Object -FilterScript { $_.Name -ne $Identity } if ($Confirm -ne $false) { Write-Host 'Do you really want to permanently remove the connection '$Identity -ForegroundColor Yellow Write-Host -Object '[Y] Yes [N] No (default is "N"): ' -NoNewline -ForegroundColor Yellow $cv = Read-Host if ($cv -ne 'Y') { return $null } } $ECMConfig |Export-Clixml ($pspp + 'ECM.config') } function Set-ECMConnection { param( [Parameter(Mandatory = $true)] [string] $Identity, [string] $NewIdentity, [string] $Prefix, [switch] $ChangeUnlimitedEnumerationSettings, [switch] $Credentials, [switch] $ClearPrefix, [switch] $ShowSCC, [switch] $ShowEOP ) $ECMConfig = Get-ECMConnection $ConnectionUpdate = $ECMConfig |Where-Object -FilterScript { $_.Identity -eq $Identity } if ($ConnectionUpdate -eq $null) { Write-Error ('Connection ' + $Identity + ' not found') return } if ($Prefix -ne $null -and $Prefix -notlike '') { $ConnectionUpdate.Prefix = $Prefix } if ($NewIdentity -ne $null -and $NewIdentity -notlike '') { $ConnectionUpdate.Identity = $NewIdentity } if ($ChangeUnlimitedEnumerationSettings -eq $true) { if ($ConnectionUpdate.UnlimitedEnumeration -eq $true) { $ConnectionUpdate.UnlimitedEnumeration = $false } else { $ConnectionUpdate.UnlimitedEnumeration = $true } } if ($Credentials -eq $true) { $ConnectionCredentials = Get-Credential -Message ('New Credentials for connection ' + $Identity) if ($ConnectionCredentials -eq $null) { Write-Error ('Credentials are mandatory. Please try again.') return } $ConnectionUpdate.UserName = $ConnectionCredentials.UserName $ConnectionUpdate.Password = ($ConnectionCredentials.Password |ConvertFrom-SecureString) } if ($ClearPrefix -eq $true) { $ConnectionUpdate.Prefix = $null } if ($ShowSCC -eq $true) { $ConnectionUpdate.SCCHidden = $false } else { $ConnectionUpdate.SCCHidden = $true } if ($ShowEOP -eq $true) { $ConnectionUpdate.EOPHidden = $false } else { $ConnectionUpdate.EOPHidden = $true } $ECMConfigNew = @() $ECMConfig = Get-ECMConnection |Where-Object -FilterScript { $_.Identity -ne $Identity } $ECMConfigNew += $ECMConfig $ECMConfigNew += $ConnectionUpdate $ECMConfigNew |Export-Clixml ($pspp + 'ECM.config') } $pspp = $profile -replace 'Microsoft.PowerShell_profile.ps1' $pspp = $pspp -replace 'Microsoft.PowerShellISE_profile.ps1' ################ #Discontinued ################ function New-ExchangeCredentials { <# .SYNOPSIS Add a new Exchange Connection to use with Connect-Exchange .DESCRIPTION Add a new Exchange Connection to use with Connect-Exchange .EXAMPLE Connect-Exchange -ConnectionName 'Customer Exchange PROD' [CmdletBinding(DefaultParametersetName = 'None')] param ( # Parameter description [Parameter(Mandatory = $true)] [string] $ConnectionName, [Parameter(ParameterSetName = 'ConnectionType',Mandatory = $false)][switch]$OnPrem, [Parameter(ParameterSetName = 'ConnectionType',Mandatory = $true)][string]$URI, [Parameter(Mandatory = $false)] [switch] $UnlimitedEnumerationLimit ) Write-Host -Object '[ECM] Enter credentials for your new connection' -ForegroundColor Yellow $ConnectionCredentials = Get-Credential -Message ('Credentials for connection ' + $ConnectionName) $ConnectionDB = @() $NewConnectionDB = @() if ($URI -like '') { $URI = 'https://outlook.office365.com/powershell-liveid/' } if ((Test-Path -Path ($pspp + 'ECM.config')) -eq $false) { $ConnectionDBProperties = @{ 'Connection' = $ConnectionName 'UserName' = $ConnectionCredentials.UserName 'Password' = ($ConnectionCredentials.Password |ConvertFrom-SecureString) 'ConnectionURI' = $URI 'UnlimitedEnumerationLimit' = $UnlimitedEnumerationLimit } $ConnectionDB += New-Object -TypeName pscustomobject -Property $ConnectionDBProperties $ConnectionDB | Export-Clixml ($pspp + 'ECM.config') } else { $ConnectionDB = Import-Clixml ($pspp + 'ECM.config') foreach ($element in $ConnectionDB) { if ($element.Connection -eq $ConnectionName) { Write-Host '[ECM ERROR] A Connection with that name is already present (' $ConnectionName '). Please specify another name.' -ForegroundColor Red return } $ConnectionDBProperties = @{ 'Connection' = $element.Connection 'UserName' = $element.UserName 'Password' = $element.Password 'ConnectionURI' = $element.ConnectionURI 'UnlimitedEnumerationLimit' = $element.UnlimitedEnumerationLimit } $NewConnectionDB += New-Object -TypeName pscustomobject -Property $ConnectionDBProperties } $ConnectionDBProperties = @{ 'Connection' = $ConnectionName 'UserName' = $ConnectionCredentials.UserName 'Password' = ($ConnectionCredentials.Password |ConvertFrom-SecureString) 'ConnectionURI' = $URI 'UnlimitedEnumerationLimit' = $UnlimitedEnumerationLimit } $NewConnectionDB += New-Object -TypeName pscustomobject -Property $ConnectionDBProperties $NewConnectionDB | Export-Clixml ($pspp + 'ECM.config') } Write-Host -Object '[ECM] Connection Database updated.' -ForegroundColor Yellow #> Write-Warning -Message 'The New-ExchangeCredentials cmdlet has been removed in this module version. Use the New-ECMConnection cmdlet instead. If you have any scripts that use the New-ExchangeCredentials cmdlet, update them to use the New-ECMConnection cmdlet.' } function Get-ExchangeCredentials { <# .SYNOPSIS List all available Exchange connections. .DESCRIPTION List all available Exchange connections. .EXAMPLE Get-ExchangeCredentials if ((Test-Path -Path ($pspp + 'ECM.config')) -ne $false) { $ConnectionDB = Import-Clixml ($pspp + 'ECM.config') $ConnectionDB |Select-Object -Property Connection, UserName, ConnectionURI } else { Write-Host '[ECM ERROR] Connection Database not found. '($pspp + 'ECM.config') -ForegroundColor Red Write-Host -Object 'Use New-ExchangeCredentials to create a new database. ' -ForegroundColor Red }#> Write-Warning -Message 'The Get-ExchangeCredentials cmdlet has been removed in this module version. Use the Get-ECMConnection cmdlet instead. If you have any scripts that use the Get-ExchangeCredentials cmdlet, update them to use the Get-ECMConnection cmdlet.' } function Remove-ExchangeCredentials { <# .SYNOPSIS Removes a connection from the connection menu. .DESCRIPTION Removes a connection from the connection menu. .EXAMPLE Remove-ExchangeCredentials -Connection 'Customer Exchange DEV' [CmdletBinding()] param ( # Parameter description [Parameter( Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true )] [string] $Connection, [switch] $NoConfirm ) process { if ((Test-Path -Path ($pspp + 'ECM.config')) -ne $false) { $ConnectionDB = Import-Clixml ($pspp + 'ECM.config') if ( ($NewConnectionDB = $ConnectionDB |Where-Object -FilterScript { $_.Connection -eq $Connection }) -eq $null) { Write-Host '[ECM ERROR] Connection Name ' $Connection ' not found.' -ForegroundColor Red return } if ($NoConfirm -eq $false) { Write-Host 'Do you really want to permanently remove the connection '$Connection -ForegroundColor Yellow Write-Host -Object '[Y] Yes [N] No (default is "N"): ' -NoNewline -ForegroundColor Yellow $cv = Read-Host } if ($cv -eq 'Y' -or $NoConfirm -eq $true) { $NewConnectionDB = $ConnectionDB |Where-Object -FilterScript { $_.Connection -ne $Connection } $NewConnectionDB | Export-Clixml ($pspp + 'ECM.config') Write-Host -Object '[ECM] Connection Database updated.' -ForegroundColor Yellow } } else { Write-Host '[ECM ERROR] Connection Database not found. '($pspp + 'ECM.config') -ForegroundColor Red } } #> Write-Warning -Message 'The Remove-ExchangeCredentials cmdlet has been removed in this module version. Use the Remove-ECMConnection cmdlet instead. If you have any scripts that use the Remove-ExchangeCredentials cmdlet, update them to use the Remove-ECMConnection cmdlet.' } function Update-ExchangeCredentials { <# .SYNOPSIS Update your connection credentials. .DESCRIPTION Update username and password for an Exchange connection used with Connect-Exchange. .EXAMPLE Update-ExchangeCredentials -Connection 'Exchange PROD' [CmdletBinding()] param ( # Parameter description [Parameter( Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true )] [string] $Connection ) process { if ((Test-Path -Path ($pspp + 'ECM.config')) -ne $false) { $ConnectionDB = Import-Clixml ($pspp + 'ECM.config') $found = $ConnectionDB |Where-Object -FilterScript { $_.Connection -eq $Connection } if ($found -ne $null) { Write-Host '[ECM] Enter new Credentials for Connection: '$Connection -ForegroundColor yellow $cred = Get-Credential -Message ('Credentials for Connection: ' + $Connection) $ConnectionDB | Where-Object -FilterScript { $_.Connection -eq $Connection }| ForEach-Object -Process { $_.Username = $cred.UserName $_.Password = ($cred.Password | ConvertFrom-SecureString) } $ConnectionDB | Export-Clixml ($pspp + 'ECM.config') Write-Host '[ECM] Credentials updatet for Connection: '$Connection -ForegroundColor yellow return } else { Write-Host '[ECM ERROR] Connection not found: '$Connection -ForegroundColor Red return } } else { Write-Host '[ECM ERROR] Connection Database not found. '($pspp + 'ECM.config') -ForegroundColor Red Write-Host -Object 'Use New-ExchangeCredentials to create a new database. ' -ForegroundColor Red } } #> Write-Warning -Message 'The Update-ExchangeCredentials cmdlet has been removed in this module version. Use the Set-ECMConnection cmdlet instead. If you have any scripts that use the Update-ExchangeCredentials cmdlet, update them to use the Set-ECMConnection cmdlet.' } |