积极答复者
Powershell脚本问题

问题
-
技术支持你们好,注释一下下面Powershell脚本,有些地方太深奥不太明白,谢谢
region Configuration
# 日志保存位置
$Logfile = "\\1\source\resource\StartUp.txt"
# 日志输出等级(值 0-2,默认值 1)
$LogLevel = 1
$WeChatVersion = "2.7.1.88"
$BandiZipVersion = "6.25.0.1"
#endregion
#region Functions
function WriteLog ($level, $text)
{
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') $env:COMPUTERNAME: $text"
if ($level -le $LogLevel)
{
Write-Output "$(Get-date -Format 'yyyy-MM-dd HH:mm:ss'),$env:COMPUTERNAME,$text" | Out-File -FilePath $Logfile -Append -Encoding unicode
}
}
#endregion
#region Main
WriteLog 2 "$($(Get-WmiObject Win32_OperatingSystem).Caption) ($env:PROCESSOR_ARCHITECTURE)"
if ($env:PROCESSOR_ARCHITECTURE -eq "x86")
{
$DestDir = $env:ProgramFiles
$DestReg = "HKLM:\Software"
}
elseif ($env:PROCESSOR_ARCHITECTURE -eq "AMD64")
{
$DestDir = ${env:ProgramFiles(x86)}
$DestReg = "HKLM:\Software\Wow6432Node"
}
else
{
WriteLog 1 "The OS platform is unidentified."
Exit
}
#Update WeChat
if (Test-Path "C:\Program Files (x86)\Tencent\WeChat\WeChatWin.dll")
{
$fileVersion = (Get-Item "C:\Program Files (x86)\Tencent\WeChat\WeChatWin.dll").VersionInfo.FileVersion
if ($fileVersion -lt $WeChatVersion)
{
WriteLog 1 "Start update WeChat: $fileVersion -> $WeChatVersion"
Start-Process "\\1\source\Software\WeChatSetup.exe" -ArgumentList "/S" -NoNewWindow -Wait
$fileVersion = (Get-Item "C:\Program Files (x86)\Tencent\WeChat\WeChatWin.dll").VersionInfo.FileVersion
if ($fileVersion -ne $WeChatVersion)
{
WriteLog 1 "Error to update WeChat: $fileVersion"
}
else
{
WriteLog 1 "Finish to update WeChat: $fileVersion"
}
}
else
{
WriteLog 1 "Found WeChat: $fileVersion"
}
}
else
{
WriteLog 1 "Not Found WeChat"
}
#Update BandiZip
if (Test-Path "C:\Program Files\Bandizip\Bandizip.exe")
{
$fileVersion = (Get-Item "C:\Program Files\Bandizip\Bandizip.exe").VersionInfo.FileVersion
if ($fileVersion -lt $BandiZipVersion)
{
WriteLog 1 "Start update BandiZip: $fileVersion -> $BandiZipVersion"
Start-Process "\\1\source\Software\BANDIZIP-SETUP.exe" -ArgumentList "/S" -NoNewWindow -Wait
$fileVersion = (Get-Item "C:\Program Files\Bandizip\Bandizip.exe").VersionInfo.FileVersion
if ($fileVersion -ne $BandiZipVersion)
{
WriteLog 1 "Error to update BandiZip: $fileVersion"
}
else
{
WriteLog 1 "Finish to update BandiZip: $fileVersion"
}
}
else
{
WriteLog 1 "Found BandiZip: $fileVersion"
}
}
else
{
WriteLog 1 "Not Found BandiZip"
}
#endregion- 已编辑 45度半 2020年7月6日 3:21
答案
-
这个脚本不确定是否是完整的升级脚本且与日志有关,主要有两个升级的,一个是wechat,应该是微信,另一个是BandiZip。
在脚本中有标记如果升级成功,会提示什么,如果升级失败,会提示什么。
并且,在脚本中已经有一定的注解,在符号#后面的一般为对于该段落的注释。
Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.- 已编辑 Yang YoungMicrosoft contingent staff 2020年7月6日 8:18
- 已标记为答案 45度半 2020年7月7日 1:58
全部回复
-
Hi,
关于基于powershell的问题,建议您咨询以下论坛的专家以获取专业支持:
https://social.technet.microsoft.com/Forums/windowsserver/en-US/home?forum=winserverpowershell
此外,建议您详细描述一下您的主要疑问点,以方便论坛内的成员针对性解答。
如果您需要进一步支持请联系我们。
祝好,
Young YangPlease remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com. -
您需要的解释是指对于脚本命令的详细解释,还是针对这个脚本是做什么的解释呢
Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com. -
这个脚本不确定是否是完整的升级脚本且与日志有关,主要有两个升级的,一个是wechat,应该是微信,另一个是BandiZip。
在脚本中有标记如果升级成功,会提示什么,如果升级失败,会提示什么。
并且,在脚本中已经有一定的注解,在符号#后面的一般为对于该段落的注释。
Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.- 已编辑 Yang YoungMicrosoft contingent staff 2020年7月6日 8:18
- 已标记为答案 45度半 2020年7月7日 1:58
-
非常高兴得知您的问题得以解决,如果您觉得我的回答对您有所帮助,请将其标注为答案。
Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.