A user asked about testing file share availability which can be done wtih a Shell Scout – this can be done using a PowerShell script that checks the share and exits with a code != 0 if it fails. To handle permission access issues, a PowerShell script can be amended by adding a credential to the test-path command. More information can be found at: https://support.controlup.com/docs/shell-execution and https://devblogs.microsoft.com/scripting/powertip-test-the-presence-of-a-remote-share-by-using-powershell/.
Read the entire ‘Testing File Share Availability Using a Shell Scout’ thread below:
Hi everyone. I’m new to scoutbees and was wondering If anyone had done anything around testing a file share availability.
This could easily be done with a shell scout.
https://support.controlup.com/docs/shell-executionBasically have a script check the share. If it fails have the script exit with a return code of something other than 0.
Oh ok. That makes sense. I’m going to give it a try. Thanks for your help. I’m still trying to learn all the custom things the scouts can do.
@member – Welcome to Scoutbees. This is the perfect place to ask questions and get some great ideas on how to’s
Thanks @member. It’s been very helpful so far.
@member can you share what you got to work?
$result = test-path \nas\files2
if ($result -eq $false){
write-host "Share not found."
Exit(1)
}I’ll check that out. I tried Get-ChildItem -path "UNC path to share name" -filter "a file I know exists here" -recurse
It works. I see exit code 0, but the stderr length show an access denied at path to ps1 file.
File: powershell.exe
Arguments: -file c:\tech\scripts\find_files.ps1
Date: Mon, 12 Dec 2022 17:12:57
Exit Code: 0
STDERR Length: test-path : Access is denied At C:\tech\scripts\find_files.ps1:2 char:1 + test-path \1001-2019-fs01\Core + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : PermissionDenied: (\1001-2019-fs01\Core:String) [Test-Path], UnauthorizedAccessException + FullyQualifiedErrorId : ItemExistsUnauthorizedAccessError,Microsoft.Powe rShell.Commands.TestPathCommand b
STDOUT Body:
FalsePretty sure you going to need to copy the ps1 local to the hive.
That’s what I get with:
test-Path \fileshare name
When I run in powershell it returns: True
Well… Stupid me. So the hive runs as localsystem and so does the powershell script. The system account doesn’t have rights to the share so this doesn’t work.
I’ll double check the share permissions. It should be set with domain users read execute. I’m seeing the scout as successful in scoutbees.
I tested using PSExec -s. Doesn’t work.
The ps1 file is on the hive server in c:\tech\scripts
Same here. c:\temp
Access denied is when running test-path. It doesn’t have permissions.That’s what it looks like but the test says successful.
Same here but its not.
You would have to change this script to use a credential for the test-path command.Are you getting access denied to the script or to the share?
Share. Running everything manually as system. System doesn’t have read rights.
I was able to get mine working. I gave EVERYONE read access to a file on the share.
Continue reading and comment on the thread ‘Testing File Share Availability Using a Shell Scout’. Not a member? Join Here!
Categories: All Archives, ControlUp Scoutbees, ControlUp Scripts & Triggers