functions/restart-d365environment.ps1


<#
    .SYNOPSIS
        Restart the different services
         
    .DESCRIPTION
        Restart the different services in a Dynamics 365 Finance & Operations environment
         
    .PARAMETER ComputerName
        An array of computers that you want to work against
         
    .PARAMETER All
        Instructs the cmdlet work against all relevant services
         
        Includes:
        Aos
        Batch
        Financial Reporter
        DMF
         
    .PARAMETER Aos
        Instructs the cmdlet to work against the AOS (IIS) service
         
    .PARAMETER Batch
        Instructs the cmdlet to work against the Batch service
         
    .PARAMETER FinancialReporter
        Instructs the cmdlet to work against the Financial Reporter (Management Reporter 2012)
         
    .PARAMETER DMF
        Instructs the cmdlet to work against the DMF service
         
    .EXAMPLE
        PS C:\> Restart-D365Environment -All
         
        This will stop all services and then start all services again.
         
    .EXAMPLE
        PS C:\> Restart-D365Environment -ComputerName "TEST-SB-AOS1","TEST-SB-AOS2","TEST-SB-BI1" -All
         
        This will work against the machines: "TEST-SB-AOS1","TEST-SB-AOS2","TEST-SB-BI1".
        This will stop all services and then start all services again.
         
    .EXAMPLE
        PS C:\> Restart-D365Environment -Aos -Batch
         
        This will stop the AOS and Batch services and then start the AOS and Batch services again.
         
    .NOTES
        Tags: Environment, Service, Services, Aos, Batch, Servicing
         
        Author: Mötz Jensen (@Splaxi)
         
#>

function Restart-D365Environment {
    [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidDefaultValueSwitchParameter", "")]
    [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
    [CmdletBinding(DefaultParameterSetName = 'Default')]
    
    param (
        [Parameter(Mandatory = $false, ParameterSetName = 'Default', Position = 1 )]
        [Parameter(Mandatory = $false, ParameterSetName = 'Specific', Position = 1 )]
        [string[]] $ComputerName = @($env:computername),

        [Parameter(Mandatory = $false, ParameterSetName = 'Default', Position = 2 )]
        [switch] $All = $true,

        [Parameter(Mandatory = $false, ParameterSetName = 'Specific', Position = 2 )]
        [switch] $Aos,

        [Parameter(Mandatory = $false, ParameterSetName = 'Specific', Position = 3 )]
        [switch] $Batch,

        [Parameter(Mandatory = $false, ParameterSetName = 'Specific', Position = 4 )]
        [switch] $FinancialReporter,

        [Parameter(Mandatory = $false, ParameterSetName = 'Specific', Position = 5 )]
        [switch] $DMF
    )

    Stop-D365Environment @PSBoundParameters

    Start-D365Environment @PSBoundParameters
}