簡體   English   中英

在另一個 Powershell 腳本中運行 Powershell 腳本

[英]Running a Powershell script inside another Powershell script

我和我的同事正在開發一組腳本,與 Windows 成像器和配置設計器 (WICD) 一起使用,為新 PC 提供定制軟件並去除一堆討厭的東西。 我們讓所有組件獨立工作,我們只需要將它們串在一起,這樣它們就可以同時運行,幾乎不需要用戶干預。 以下是其工作原理的細分:

Get to OOBE experience where you select region
Plug in USB drive with provisioning package at the root of the USB drive
Let things run

First script (install) creates working directories, downloads scripts from github repo, skips OOBE turning off everything, creates admin user and password, enables auto logon, uses a run once registry key to run second script.

Second script (cleanup) Waits 30 seconds to let the registry populate
Resets privacy settings, disables auto logon, deletes stored credentials, installs a piece of software, and lastly runs another script which installs more software and strips a bunch of bloatware out of Windows.

或者,至少它應該運行最后一個腳本。 這是我唯一沒有工作的事情。 我可以通過日志文件和 output 判斷它嘗試運行腳本,但它所做的只是啟動腳本,然后在沒有任何 output、回溯或任何表明它失敗的情況下退出,除了 Z3D265B4E1EEB8DCCZ3 提示。 以下是清理腳本的經過清理和編輯的版本。 讓這個其他腳本運行我做錯了什么嗎? 還有另一種方法我應該接近這個。 任何幫助是極大的贊賞。

如果您願意,我還可以發布安裝腳本和 Windows 清理。 第 24 行是我遇到障礙的地方。

Start-Transcript -Append C:\Support\Logs\PostDeploymentCleanupLog.txt

#Wait for registry to populate
Start-Sleep -s 30

# Reset Privacy settings to default
reg delete HKLM\SOFTWARE\Policies\Microsoft\Windows\OOBE /v DisablePrivacyExperience /f

# Disable autoLogon
REG ADD "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon /t REG_SZ /d 0 /f

# Remove stored credentials
REG DELETE "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword /f


# Start SomeSoftware installer in quiet mode
Function Install-SomeSoftware {...} #End Function Install-SomeSoftware


Install-SomeSoftware -Server '<redacted>' -LocationID <redacted> -Token '<redacted>' -Silent -Force -Transcript

# Run WindowsSetup2_0-WIP
# Forked from SomeGuy's GitHub repo
PowerShell.exe -ExecutionPolicy Bypass -File C:\Support\Scripts\WindowsSetup2_0.ps1

#Remove unneeded directories
Remove-Item -Path C:\\Support\\Scripts -Recurse -Verbose
Remove-Item -Path C:\\Support\\Installers -Recurse -Verbose

Stop-Transcript

我在我的 WindowsSetup 腳本中發現了一個錯誤,導致 cmd 實例打開而不關閉,從而破壞了腳本。

& "PowerShell.exe -ExecutionPolicy Bypass -File C:\Support\Scripts\WindowsSetup2_0.ps1"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM