Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


PowerShell - how can I make a script that first find the file - then run it
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

PowerShell - how can I make a script that first find the file - then run it

myhkenmyhken Member
edited November 2017 in General

Hello.

I'm currently trying to clean up an old N-able AV defender installation on around 200 servers and workstations. It all the devices there n-able did not remove AV defender automatically.
Since most of the devices is workstations, there is a lot of work removing AV defender. I have to call each customer, schedule time to work on the device, then remove, then do it all over.

But all I need to do if I want to script this, is to start and run the file installer.exe.
The file is put in different folders on all devices, and it need to have access to a installer.xml that's unique for each device.

The only thing that's common on each device is this folder: "C:\Program Files\N-able Technologies\EndpointSetupInformation\"
Then they are using folders like this: {3c1c1be4-129c-485d-e43b-8183cf91c692}\ that's different for each device. And under that folder is the installer.exe and installer.xml

So how can I script that I always find the correct folder and run the correct installer.exe file?

Comments

  • mikhomikho Member, Host Rep

    You can start with
    $path = "C:\Program Files\N-able Technologies\EndpointSetupInformation\" Get-ChildItem -Path $path -Recurse -Filter "DiffieHellman.dll" | Select DirectoryName | ft -hidetableheaders

    That way you find the directories where Installer.exe is.
    Check if there are an installer.xml in that directory and if it is, execute Installer.exe

    Thanked by 1myhken
  • djndjn Member
    edited November 2017

    @echo off

    for /r "C:\Program Files\N-able Technologies\EndpointSetupInformation" %%a in (*) do if "%%~nxa"=="installer.exe" set p=%%~dpnxa

    if defined p (

    (start "" "%p%")

    ) else (

    echo File not found

    )

    pause

    This old .bat I use for job like yours may help or does it have to be powershell

    Thanked by 1myhken
  • Edit to check for xml
    https://pastebin.com/raw/GgWgF8k7

    Thanked by 1myhken
  • @mikho said:
    You can start with
    $path = "C:\Program Files\N-able Technologies\EndpointSetupInformation\" Get-ChildItem -Path $path -Recurse -Filter "DiffieHellman.dll" | Select DirectoryName | ft -hidetableheaders

    That way you find the directories where Installer.exe is.
    Check if there are an installer.xml in that directory and if it is, execute Installer.exe

    This was closest to my solution. Better then my own, since I needed two $paths to do the job you did with one. So thank you.

  • wrote my first poweshell script :) allways worked with batch files as I am a old git
    https://pastebin.com/raw/kEGwLvti
    It works unless there is more than 1 installer.exe in the path

    Thanked by 1myhken
Sign In or Register to comment.