0

I'm trying to create a script on a Flashdrive to run several commands on all of our company computers. In this specific part I'm trying to run commands for AVAST to run a virus scan and do updates at 10 pm. The problem i'm running into is: in order to run these commands I have to navigate to the folder where the Avast software is. Thing is the drive letter might vary per computer.... so I'm not sure if I'm able to use a wildcard or how I would go about this. My current script is:

echo off
cd "$((get-location).drive.name):\Program Files (x86)\Avast Software"
ashupd.exe/vps
ashupd.exe/program
ashcmd.exe/*
pause

This only gets the current drive letter... which would be the flashdrive I'm running the script off of. So that's no good.

Donald Duck
  • 8,409
  • 22
  • 75
  • 99
  • Are you looking for [Get-PSDrive](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-psdrive)? – maio290 Apr 26 '22 at 20:17
  • That just shows a list of drives, right? would I be able to use that in my script? We are trying to make the script a 1-2 click and done sort of thing. So we cant go around and run that command to find the drive manually for every individual computer... as we have hundreds of computers and it would take a lot of time – Adam Lipman Apr 26 '22 at 20:22
  • 1
    You can usually get the installation path of an installed program from the registry. As an educated guess have a look at `HKEY_LOCAL_MACHINE\Software\Avast` or `HKEY_LOCAL_MACHINE\Software\Wow6432Node\Avast` using RegEdit. There is propably a value named `InstallPath` or similar. Using PowerShell, you could get its value like this: `(Get-ItemProperty 'hklm:\Software\Avast' -Name InstallPath).InstallPath` – zett42 Apr 26 '22 at 20:27
  • You'd need to iterate over the drives and check whether your location or files you want to execute actually reside in there. If the computers within the company are installed the same way, you may have luck with using [one of Windows' environment variables](https://learn.microsoft.com/en-us/windows/deployment/usmt/usmt-recognized-environment-variables) and/or iterating over the individual drives. But you'd probably be better off using the registry keys of the installed software to determine their installation path. – maio290 Apr 26 '22 at 20:28

1 Answers1

0

I have this little test saved for when I need to trying both 32bit and 64bit paths.

$var = Get-WmiObject win32_operatingsystem

if ($var.osarchitecture -like "64*") {
    #64 bit logic here
    $path = \path\to\64x\
}
else {
    #32 bit logic here
    $path = \path\to\86x\
}
  • The `[System.Environment]::Is64BitOperatingSystem` [property](https://learn.microsoft.com/en-us/dotnet/api/system.environment.is64bitoperatingsystem?view=netframework-4.8#system-environment-is64bitoperatingsystem) is another way to determine if the OS is x64/x86. – Paul π Feb 15 '23 at 22:17