Kaseya Community

Script to find and change permissions on each file named X

  • I was hoping it's possible to create a script that will:

    1) Find any instances of a certain filename on a server
    2) Add a user/permission to that file

    In other words:

     

    Find each instance of file.dll

    For each instance of file.dll add the user EVERYONE to the file permissions, and give EVERYONE full access to any files found.

    Is this possible, or posibly too difficult to script when doing this manually would only take about 15 minutes?

    Thanks!

    Gavin

  • It could be done using a FOR loop in the command line...   first put in the command  to find the file (Dir /s) then to run CACLS on the files found to modify permission.

    These links might help:

    www.robvanderwoude.com/for.php

    www.cyberciti.biz/.../windows-change-access-permissions-from-the-command-line.html

    I'll try to circle back here if I get a chance today. This is very reasonable to do in a Kaseya script - we can kick it off, collect the results and save them to the server, and even have some sort of alert/notification mechanism put in place if a file is found and permission is modified (or lack thereof).



    [edited by: Ben at 7:17 AM (GMT -8) on 2-10-2011] .
  • We use this to change permissions on some sql files - I got this along time ago from the forum.

    uses forfiles.exe which is a windows tool don't think it is on Winxp but if not you can add a step to drop it down copy the file from a win2k3 server.

    Scans the disk anywhere it finds the file it add permissions.

    <?xml version="1.0" encoding="utf-8"?>

    <ScriptExport xmlns:xsi="www.w3.org/.../XMLSchema-instance" xmlns:xsd="www.w3.org/.../XMLSchema" xmlns="www.kaseya.com/.../Scripting">

     <Procedure name="Clean up Perflib errors on C, D, and E" treePres="3" id="54827327">

       <Body description="This script fixes permissions on sqlctr80.dll file under SQL directories that causes problems with Kaseya and generates PERFLIB errors in the application event l">

         <If description="This script fixes permissions on sqlctr80.dll file under SQL directories that causes problems with Kaseya and generates PERFLIB errors in the application event l">

           <Condition name="True" />

           <Then>

             <Statement name="GetVariable" continueOnFail="false">

               <Parameter xsi:type="EnumParameter" name="VariableType" value="AgentInstallDrive" />

               <Parameter xsi:type="StringParameter" name="SourceContent" value="" />

               <Parameter xsi:type="StringParameter" name="VariableName" value="agentDrv" />

             </Statement>

             <Statement name="GetVariable" continueOnFail="false">

               <Parameter xsi:type="EnumParameter" name="VariableType" value="MachineGroupID" />

               <Parameter xsi:type="StringParameter" name="SourceContent" value="" />

               <Parameter xsi:type="StringParameter" name="VariableName" value="machineName" />

             </Statement>

             <Statement name="ExecuteShellCommand" continueOnFail="false">

               <Parameter xsi:type="StringParameter" name="Command" value="forfiles.exe -p c:\ -s -m sqlctr80.dll -c "cmd /C cacls @PATH /e /g 0x22network service0x22:r >> #agentDrv#temp\sqlfiles.txt"" />

               <Parameter xsi:type="EnumParameter" name="ExecuteAccount" value="System" />

               <Parameter xsi:type="BooleanParameter" name="Is64Bit" value="False" />

             </Statement>

             <Statement name="ExecuteShellCommand" continueOnFail="false">

               <Parameter xsi:type="StringParameter" name="Command" value="forfiles.exe -p d:\ -s -m sqlctr80.dll -c "cmd /C cacls @PATH /e /g 0x22network service0x22:r >> #agentDrv#temp\sqlfiles.txt"" />

               <Parameter xsi:type="EnumParameter" name="ExecuteAccount" value="System" />

               <Parameter xsi:type="BooleanParameter" name="Is64Bit" value="False" />

             </Statement>

             <Statement name="ExecuteShellCommand" continueOnFail="false">

               <Parameter xsi:type="StringParameter" name="Command" value="forfiles.exe -p e:\ -s -m sqlctr80.dll -c "cmd /C cacls @PATH /e /g 0x22network service0x22:r >> #agentDrv#temp\sqlfiles.txt"" />

               <Parameter xsi:type="EnumParameter" name="ExecuteAccount" value="System" />

               <Parameter xsi:type="BooleanParameter" name="Is64Bit" value="False" />

             </Statement>

             <Statement name="GetVariable" continueOnFail="false">

               <Parameter xsi:type="EnumParameter" name="VariableType" value="FileContent" />

               <Parameter xsi:type="StringParameter" name="SourceContent" value="#agentDrv#temp\sqlfiles.txt" />

               <Parameter xsi:type="StringParameter" name="VariableName" value="Sqlfiles" />

             </Statement>

             <Statement name="SendEmail" continueOnFail="false">

               <Parameter xsi:type="StringParameter" name="To" value="mmartin@itfocus.ie" />

               <Parameter xsi:type="StringParameter" name="Subject" value="#machineName#" />

               <Parameter xsi:type="StringParameter" name="Body" value="#Sqlfiles#" />

             </Statement>

             <Statement name="DeleteFile" continueOnFail="false">

               <Parameter xsi:type="StringParameter" name="Path" value="#agentDrv#temp\sqlfiles.txt" />

             </Statement>

           </Then>

         </If>

       </Body>

     </Procedure>

    </ScriptExport>

  • LOL! Those are the excact files we have to change :)

    Thanks!!