I'm trying to create a script that counts every file in a folder. The count part on its own works fine but I'm looking to make it output an exit code based off of the count for use in an automation tool.
value | message | exit code
=15 "finish OK" (0)
<15 "not ready" (1)
>15 "corruption" (2)
I tried the below, but it says "line 2 char 14 cannot bind argument to parameter 'path' because it is null"
$filecount = Write-Host ( Get-ChildItem -File "c:\test\" | Measure-Object ).Count
if(test-path $filecount){
if((get-item $filecount).Count = 15){
"Finish OK";EXIT 0
}
if((get-item $filecount).Count > 15){
"CORRUPTION";EXIT 2}
else{"REVIEW DATA"}
}
else{"NOT READY";EXIT 1}