# Get a count of files in a directory.
$directory_file_count = "0"
$server_directory_string = "\\WISEFAQDC\c$\downloads"
# check that the directory exists.
$does_directory_exist = (Test-Path $server_directory_string)
# if it does, then continue
# file count does include directories but not a count of their contents.
$directory_file_count = (get-childitem $server_directory_string -name).count
Write-Host "Directory file count: $directory_file_count"
# directory doesn't exist
Write-Host "Directory $server_directory_string - DOES NOT EXIST"
The only problem with this code is that file count does include directories, but not their contents, in it’s count of files.