Git-PullUser.ps1

function Git-PullUser {
  [CmdletBinding()]
  [alias('GPull')]
  param(
    [switch]$List
  )
  dynamicparam {
    $ParamName = 'User'
    [String[]]$Values = Get-ChildItem -Path F:\vlab\git\users -Directory | % Name
    $Bucket = [Management.Automation.RuntimeDefinedParameterDictionary]::new()
    $AttributeList = [Collections.ObjectModel.Collection[System.Attribute]]::new()
    $AttribValidateSet = [ValidateSet]::new($Values)
    $AttributeList.Add($AttribValidateSet)
    $AttribParameter = [Parameter]::new()
    $AttribParameter.Mandatory = $true
    $AttributeList.Add($AttribParameter)
    $Parameter = [Management.Automation.RuntimeDefinedParameter]::new($ParamName, [String], $AttributeList)
    $Bucket.Add($ParamName, $Parameter)
    $Bucket
  }
  Begin{
    $StartDir = $PWD.Path
    $UserPath = Join-Path -Path 'F:\vlab\git\users' -ChildPath $($PSBoundParameters[$ParamName])
  }
  Process{

    switch ($List){
      $true {
        $DirList = Get-ChildItem -Path $UserPath -Directory
        return $DirList
      }
      $false {
        Set-Location -Path $UserPath
        Get-ChildItem -Path . -Directory | ForEach-Object -MemberName FullName | ForEach-Object {
          Write-Verbose -Message ('Pulling Git Repo - {0}' -f $_) -Verbose
          Set-Location -Path $_
          if (Test-Path -Path .\.git){
            git pull --all --recurse-submodules
          }
          else{
            $ermsg = ('{0} - missing .git folder' -f $_)
            Write-Error -Message $ermsg
          }
        }
        Set-Location -Path $StartDir
      }
    }
  }
}