Answer the question
In order to leave comments, you need to log in
PS script download and install BGInfo, simplify if(If)?
Good afternoon, comrades, there is a PS code for downloading and installing BGInfo from the site, it seems to me that there are a lot of ifs here to check the \BGInfo directory, to check the downloaded archive \BGInfo\BGInfo.zip, to check the bitness of the system.
If you do not check \BGInfo, the archive will not be downloaded. If you do not check the downloaded archive, it will be downloaded every time.
if(!(test-path "$adms\BGInfo")) {
New-Item -Path "$adms\BGInfo" -ItemType Directory
Invoke-WebRequest "https://download.sysinternals.com/files/BGInfo.zip" -outfile "$adms\BGInfo\BGInfo.zip"
}
Expand-Archive -path "$adms\BGInfo\BGInfo.zip" -destinationpath "$adms\BGInfo" -force
if ((Get-WmiObject win32_operatingsystem | select osarchitecture).osarchitecture -like "64*")
{
C:\Admins\Add\BGInfo\Bginfo64.exe C:\Admins\Add\BGInfo\PIT.bgi /silent /timer:00 /nolicprompt
}
else
{
C:\Admins\Add\BGInfo\Bginfo.exe C:\Admins\Add\BGInfo\PIT.bgi /silent /timer:00 /nolicprompt
}
Answer the question
In order to leave comments, you need to log in
So you still want to not download on a new one, or do you care?
You can download in $env:temp, then you don't have to check.
Create a folder for unpacking with the
-Force key, then it will not swear at its presence
.
$bits = (Get-WmiObject win32_operatingsystem).OSArchitecture -replace '\D+'
$filename = "C:\Admins\Add\BGInfo\Bginfo" + (if ($bits -eq '64) { '64' } else { '' } ) + ".exe"
$filename = "C:\Admins\Add\BGInfo\Bginfo" + @{'64'=64; '32'=32 }[$bits] + ".exe"
if (test-path $filename) .....
Thank you, adopted
$bits = (Get-WmiObject win32_operatingsystem).OSArchitecture -replace '\D+'
$bginf = "$adms\BGInfo\BGInfo" + @{'64'=64; '32'=32}[$bits] + ".exe"
if (!(test-path $bginf))
{
New-Item -Path "$adms\BGInfo" -ItemType Directory
Invoke-WebRequest "https://download.sysinternals.com/files/BGInfo.zip" -outfile "$adms\BGInfo\BGInfo.zip"
Expand-Archive -path "$adms\Bginfo\BGInfo.zip" -destinationpath "$adms\BGInfo" -force
Remove-Item "$adms\BGInfo\BGInfo.zip" -force
}
& "$bginf" "$adms\BGInfo\PIT.bgi" /silent /timer:00 /nolicprompt
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question