سؤال

I'm trying to write what is probably a very basic script (I'm far from a scripter; was drafted into doing this). The script must verify a particular drive exists, note its finding in a log file, and then if the drive does exist, it needs to execute multiple executables with arguments. After some research, I've put together the below, but with little success. I was testing it using just one executable. The results here: the script runs, but nothing is written to the log. The log file itself exists, but it's not written to.

$LogDir="E:\logs"
$Logfile = $LogDir+"BIClog.txt"
$Location = "Q:\"

Function LogWrite
{
    Param ([string]$logstring)
    Add-content $Logfile -value $logstring
}
if ((Test-Path $Location) -ne $False)
{
Logwrite "Q: drive exists. Executing BIC.exe."
& 'C:\Program Files (x86)\YardSmartServer\C3BIC.exe' "CLIENT_STATISTICS"
}
else
{
Logwrite "Q: drive does not exist."
}
هل كانت مفيدة؟

المحلول

Add "\" to the end of the $LogDir variable. Otherwise, $logfile is set to "E:\logsBIClog.txt".

$LogDir="E:\logs\"
$Logfile = $LogDir+"BIClog.txt"
...
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top