Functions/Set-Mylocation.ps1


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


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

        }
        "SharePoint2" {
            $RegKey = "HKCU:\SOFTWARE\Microsoft\OneDrive\Accounts\Business1\Tenants"
            if (!(Test-Path $RegKey)) {
                break
            }
            $Regpath = Get-ChildItem $RegKey | Where-Object PSChildName -NotLike "*OneDrive*"
            if (!($Regpath)) {
                break
            }
            $Regpath2 = $Regpath[1].Property[0]
            $Regpath3 = Split-Path $Regpath2
            $Path = $Regpath3

        }
        "CameraRoll" {
            $Date = Get-Date
            $Path = "$($env:OneDrive)\Pictures\Camera Roll\$($Date.Year)\$(Get-Date -Format "MM")"
        }
    }

    # return $Path
    if (Test-Path $Path) {
        Set-Location $Path
        if ($OpenInExplorer) {
            explorer.exe $Path
        }
    } else {
        Write-Error "$Path not found"
    }

}