Functions/Set-Mylocation.ps1


function Set-Mylocation {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory)] [ValidateSet("Git", "OneDrive", "WindowsPowershell", "WindowsPowershellProgramFiles", "Downloads", "MyDocuments", "SharePoint")] [string] $Folder,
        [Parameter()] [switch] $OpenInExplorer
    )


    switch ($Folder) {
        "Git" {
            $Path = "$([Environment]::GetFolderPath("UserProfile"))\Git"
        }
        "OneDrive" {
            $Path = $env:OneDrive
        }
        "WindowsPowershell" {
            $Path = "$([Environment]::GetFolderPath("MyDocuments"))\WindowsPowerShell"
        }
        "WindowsPowershellProgramFiles" {
            $Path = "$([Environment]::GetFolderPath("ProgramFiles"))\WindowsPowerShell"
        }
        "Downloads" {
            $Path = "$([Environment]::GetFolderPath("UserProfile"))\Downloads"
        }
        "MyDocuments" {
            $Path = "$([Environment]::GetFolderPath("MyDocuments"))"
        }
        "SharePoint" {
            $RegKey = "HKCU:\SOFTWARE\Microsoft\OneDrive\Accounts\Business1\Tenants"
            if (Test-Path $RegKey) {
                $Regpath = Get-ChildItem | Where-Object PSChildName -NotLike "*OneDrive*"
                if ($Regpath) {
                    $Regpath2 = $Regpath.Property[0]
                    $Regpath3 = Split-Path $Regpath2
                    if(Test-Path $Regpath3) {
                        $Path = $Regpath3
                    } else {
                        break
                    }
                } else {
                    break
                }


            } else {
                break
            }
        }
    }

    # return $Path
    Set-Location $Path

    if ($OpenInExplorer) {
        explorer.exe $Path
    }

}