functions/set-d365startpage.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

<#
    .SYNOPSIS
        Sets the start page in internet explorer
         
    .DESCRIPTION
        Function for setting the start page in internet explorer
         
    .PARAMETER Name
        Name of the D365 Instance
         
    .PARAMETER Url
        URL of the D365 for Finance & Operations instance that you want to have as your start page
         
    .EXAMPLE
        PS C:\> Set-D365StartPage -Name 'Demo1'
         
        This will update the start page for the current user to "https://Demo1.cloud.onebox.dynamics.com"
         
    .EXAMPLE
        PS C:\> Set-D365StartPage -URL "https://uat.sandbox.operations.dynamics.com"
         
        This will update the start page for the current user to "https://uat.sandbox.operations.dynamics.com"
         
    .NOTES
        Author: Rasmus Andersen (@ITRasmus)
        Author: Mötz Jensen (@Splaxi)
         
#>

function Set-D365StartPage() {
    [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
    [CmdletBinding(DefaultParameterSetName = 'Default')]
    param(
        
        [Parameter(Mandatory = $true, Position = 1, ParameterSetName = 'Default')]
        [String] $Name,

        [Parameter(Mandatory = $true, Position = 1, ValueFromPipelineByPropertyName = $true, ParameterSetName = 'Url')]
        [String] $Url
    )
   
    $path = 'HKCU:\Software\Microsoft\Internet Explorer\Main\'
    $propName = 'start page'
    
    if ($PSBoundParameters.ContainsKey("URL")) {
        $value = $Url
    }
    else {
        $value = "https://$Name.cloud.onebox.dynamics.com"
    }

    Set-Itemproperty -Path $path -Name $propName -Value $value
    
}