我有一个具有某些功能的Powershell脚本。但是我无法弄清楚它能否按顺序工作。有人可以帮我安排吗? #获取日期和时间 $ Timestamp =获取日期-格式yyyy-mm-dd
#Get the processor architecture
$Get_PA = [environment]::GetEnvironmentVariable("PROCESSOR_ARCHITECTURE")
if($Get_PA = "AMD64"){
$Path = "X:\CUSTOM\ODM\ODMIC\AMD64"}
else
{$Path = "X:\CUSTOM\ODM\ODMIC\AMD64\X86"}
#Get Information from uber.ini
$Get_MAC = & $Path\UIni.exe X:\uber.ini UnitInformation MACAddress FE_MAC FE_MAC.CMD
start-sleep -s 1
$Read_MAC = Get-Content .\FE_MAC.CMD
$a_MAC,$b_MAC = $Read_MAC -split "="
$Get_SN = & $Path\UIni.exe X:\uber.ini UnitInformation SerialNumber FE_SN FE_SN.CMD
start-sleep -s 1
$Read_SN = Get-Content .\FE_SN.CMD
$a_SN,$b_SN = $Read_SN -split "="
$Get_IP = & $Path\UIni.exe X:\uber.ini FILESERVER0 IP FE_IP FE_IP.CMD
start-sleep -s 1
$Read_IP = Get-Content .\FE_IP.CMD
$a_IP,$b_IP = $Read_IP -split "="
$Get_netuser = & $Path\UIni.exe X:\uber.ini FILESERVER0 netuser FE_netuser FE_netuser.CMD
start-sleep -s 1
$Read_netuser = Get-Content .\FE_netuser.CMD
$a_netuser,$b_netuser = $Read_netuser -split "="
$Get_netpass = & $Path\UIni.exe X:\uber.ini FILESERVER0 netpass FE_netpass FE_netpass.CMD
start-sleep -s 1
$Read_netpass = Get-Content .\FE_netpass.CMD
$a_netpass,$b_netpass = $Read_netpass -split "="
$Get_UBStage = & $Path\UIni.exe X:\uber.ini State downloadstage FE_UBStage FE_UBStage.CMD
start-sleep -s 1
$Read_UBStage = Get-Content .\FE_UBStage.CMD
$a_UBStage,$b_UBStage = $Read_UBStage -split "="
#-----CNT_PRISM-----#
#Connect to PRISM
$net = new-object -ComObject WScript.Network
$net.MapNetworkDrive("P:", "\\$b_IP\TempRepository\BPSAutoGM", $False, "$b_netuser", "$b_netpass")
start-sleep -s 5
#Create Working Folder if not exist
$WKFD = "$b_SN-$b_MAC"
$WKFD_Path = "P:\Logs\$WKFD"
if (![System.IO.Directory]::Exists($WKFD_Path ))
{
New-Item -ItemType Directory -Force -Path $WKFD_Path
}
$FE_ODMIC_WKFD = $WKFD_Path
#Backup Uber.ini
Copy-Item -Path X:\uber.ini -Destination "$FE_ODMIC_WKFD\$b_SN-$Timestamp-$b_UBStage-ODMIC_UBER.INI"
#-----CHK_TOAST-----#
#-----TOAST-----#
Function TOAST
{
#Delete Toast Flag
if(Test-Path -Path "$FE_ODMIC_WKFD\$b_SN-Toast.flg"){
Remove-Item "$FE_ODMIC_WKFD\$b_SN-Toast.flg"
}
#Copy logs ot working folder
Copy-Item -Path .\BPSFE_ODMIC.log -Destination "$FE_ODMIC_WKFD\$b_SN-$Timestamp-ODMIC_Toast_FEWDTTST.log"
#Toast
$Path_Toast = "X:\Tools\WinToast\"
$Run_Toast = & $Path_Toast\WinToast.exe /U /PHSA /NA
start-sleep -s 3
#Disconnect to PRISM
& net use P: /delete /yes
start-sleep -s 3
& net use Q: /delete /yes
start-sleep -s 3
#Reboot
Restart-Computer
}
#Check for Toast flag
if(Test-Path -Path "$FE_ODMIC_WKFD\$b_SN-Toast.flg")
{
#GOTO TOAST#
TOAST
}
else
{
"Toast flag not found"
}
#-------------------------------------------------------------#
#Auto GM Selection
Function Call_GUI
{
#Run GUI to choose AutoGM
& .\run_gui_1.cmd
start-Sleep -s 1
$Log = Get-Content .\log.txt | Where-Object {$_.Contains("600")}
if(
($Log) -and
(![System.IO.Directory]::Exists("$FE_ODMIC_WKFD\AUTOGM")) -and
(![System.IO.Directory]::Exists("$FE_ODMIC_WKFD\AUTOGM\JOB")) -and
(![System.IO.Directory]::Exists("$FE_ODMIC_WKFD\AUTOGM\POfile")) -and
(![System.IO.Directory]::Exists("$FE_ODMIC_WKFD\AUTOGM\AutoGM.flg"))
){
New-Item -ItemType Directory -Force -Path "$FE_ODMIC_WKFD\AUTOGM"
New-Item -ItemType Directory -Force -Path "$FE_ODMIC_WKFD\AUTOGM\JOB"
New-Item -ItemType Directory -Force -Path "$FE_ODMIC_WKFD\AUTOGM\POfile"
New-Item -ItemType File -Force -Path "$FE_ODMIC_WKFD\AUTOGM\AutoGM.flg"
CHK_GM_STAGE
}
else
{
END_Proc
}
}
#-----AUTOGM_SELECT-----#
Function AUTOGM_SELECT
{
#Manually GM or Auto GM selection GUI
if(Test-Path -Path "$FE_ODMIC_WKFD\AUTOGM\AutoGM.flg")
{
CHK_GM_STAGE
}
else
{
Call_GUI
}
}
#-----GET_DASH_MODE-----#
#Get DASH Mode
$Get_SKU = & $Path\BiosConfigUtility.exe /getvalue:"SKU Number" | Where-Object {$_.Contains("@ODM@GM")}
if($Get_SKU)
{
$MLGM2ODM = "1"
AUTOGM_SELECT
}
else
{
END_Proc
}
Function CHK_GM_STAGE
{
#AUTO GM
if($MLGM2ODM -eq "1" -and $b_UBStage -eq "101")
{
GM_BEGIN
}
if($MLGM2ODM -eq "1" -and $b_UBStage -eq "444")
{
GM_END
}
else
{
END_Proc
}
}
#-----GM_BEGIN-----#
Function GM_BEGIN
{
& .\2_GUI_Default_Folder.ps1
}
#-----CHK_GM_STAGE-----#
#-----GM_END-----#
Function GM_END
{
}
#-----END_PROCESS-----#
Function END_Proc
{
#Copy logs ot working folder
#Disconnect to PRISM
& net use P: /delete /yes
start-sleep -s 3
& net use Q: /delete /yes
start-sleep -s 3
}
我尝试了此代码,但是它不能顺序工作,因此某些功能不起作用。我该如何安排好,请帮助我。谢谢。
答案 0 :(得分:1)
正如Lee_Dailey建议的[咧嘴]一样,使用Start-Process -Wait
运行外部程序:
Start-Process -FilePath "<exe>" -ArgumentList @(arg1,arg2) -NoNewWindow -Wait
答案 1 :(得分:1)
您是说UIni在后台运行吗?如果输出文本,那将是奇怪的。将其传递到Write-Output可能是使Powershell等待更轻松的方法。而且,如果您使用UIni的完整路径,则不需要'&'。