functions/restart-d365environment.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99

<#
    .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
         
    .PARAMETER ShowOriginalProgress
        Instruct the cmdlet to show the standard output in the console
         
        Default is $false which will silence the standard output
         
    .EXAMPLE
        PS C:\> Restart-D365Environment -All
         
        This will stop all services and then start all services again.
         
    .EXAMPLE
        PS C:\> Restart-D365Environment -All -ShowOriginalProgress
         
        This will stop all services and then start all services again.
        The progress of Stopping the different services will be written to the console / host.
        The progress of Starting the different services will be written to the console / host.
         
    .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,

        [Parameter(Mandatory = $False)]
        [switch] $ShowOriginalProgress
    )

    Stop-D365Environment @PSBoundParameters | Format-Table

    Start-D365Environment @PSBoundParameters | Format-Table
}