How to navigate to a file in an unknown drive letter (powershell)

319 views Asked by At

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.

1

There are 1 answers

1
another victim of the mouse On

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\
}