PolicySetup/PolicySetup.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
Set-StrictMode -Version Latest
function Install-AzSKOrganizationPolicy
{
    <#
    .SYNOPSIS
    This command is intended to be used by central Organization team to setup Organization specific policies
    .DESCRIPTION
    This command is intended to be used by central Organization team to setup Organization specific policies
 
    #>

    
    [OutputType([String])]
    Param
    (
        [string]
        [Parameter(Mandatory = $true, Position = 0)]
        [ValidateNotNullOrEmpty()]
        $SubscriptionId,

        #[Parameter(Mandatory = $false)]
        #[string]
        #$ResourceGroupName,

        [Parameter(Mandatory = $false)]
        [string]
        $ResourceGroupLocation = "EastUS2",

        [Parameter(Mandatory = $true)]
        [string]
        $OrgName,

        [Parameter(Mandatory = $false)]
        [string]
        $DepartmentName,

        [Parameter(Mandatory = $false)]
        [string]
        $PolicyFolderPath
    )

    Begin
    {
        [CommandHelper]::BeginCommand($PSCmdlet.MyInvocation);
        [ListenerHelper]::RegisterListeners();
    }
    Process
    {
        try 
        {
            $policy = [PolicySetup]::new($SubscriptionId, $PSCmdlet.MyInvocation, $OrgName, $DepartmentName, $ResourceGroupLocation, $PolicyFolderPath);
            if ($policy) 
            {
                return $policy.InvokeFunction($policy.InstallPolicy);
            }
        }
        catch 
        {
            [EventBase]::PublishGenericException($_);
        }  
    }
    End
    {
        [ListenerHelper]::UnregisterListeners();
    }
}