Skip to content

Instantly share code, notes, and snippets.

Created Jul 21, 2019
What would you like to do?
Iron Scripter july, 19 2019 - Advanced
function Get-FileInfo {
param (
# The Path parameter takes an array of strings to query. Pipe away if desired
[Parameter(ParameterSetName = 'Local')]
[Parameter(ParameterSetName = 'Remote')]
# The ComputerName parameter takes several computernames and executes the Get-FileInfo command against them
[Parameter(ParameterSetName = 'Remote')]
# The Credential parameter takes a credential object if required to execute remote commands against the computers specified in the ComputerName parameter
[Parameter(ParameterSetName = 'Remote')]
# The AsJob switch runs the command as a job on the remote machine
[Parameter(ParameterSetName = 'Remote')]
# The JobName parameter lets you specify a name for the job
[Parameter(ParameterSetName = 'Remote')]
begin {
$s = [scriptblock]::Create('param ($path) foreach ($p in $Path){
if (Test-Path $p){
try {
Get-ChildItem $p -Recurse -Force |
measure-object length -sum -Average -ErrorAction Stop |
select-object Count,Sum,Average,@{n="Date";e={Get-date}},@{n="ComputerName";e={hostname}},@{n="Path";e={$p}}
} catch {
Write-Verbose "No files in $p"
} else {
Write-Warning "$p does not exist!"
process {
$paramHash = @{
ScriptBlock = $s
ArgumentList = $Path
if ($AsJob){$paramHash.Add('AsJob',$True)}
if ($JobName -and $AsJob){$paramHash.Add('JobName',$JobName)}
if ($ComputerName){$paramHash.Add('ComputerName',$ComputerName)}
if ($Credential){$paramHash.Add('Credential',$Credential)}
Invoke-Command @paramHash
end {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment