小编Abr*_*xas的帖子

PowerShell 提示继续执行代码

我有一个用于自动化WSUS进程的脚本,它的最后一个阶段继续删除所有旧的/不必要的文件/对象。

我想在清理阶段之前提示“按‘回车’继续删除或任何其他键停止”,让人们可以选择不运行它。

我目前在脚本末尾的代码在这里:

Get-WsusServer 10.1.1.25 -PortNumber 8530 | Get-WsusUpdate -Classification All -Approval Unapproved -Status FailedOrNeeded | Approve-WsusUpdate -Action Install -Target $ComputerTarget -Verbose

Write-Host "Updates have been approved!"
Write-Host "Preparing to clean WSUS Server of obsolete computers, updates, and content files."

#Part2 - WSUS Server Cleanup

##Run Cleanup Command
Get-WsusServer $WSUS_Server -PortNumber $PortNumber | Invoke-WsusServerCleanup -CleanupObsoleteComputers -CleanupObsoleteUpdates -CleanupUnneededContentFiles
Run Code Online (Sandbox Code Playgroud)

就在#Part2 之前,我想要提示“按回车继续或任何其他键中止”

有没有一种简单的方法可以做到这一点?

我所看到的一切似乎都涉及将整个脚本嵌套在我不想这样做的代码块中。=/

scripting powershell

15
推荐指数
3
解决办法
5万
查看次数

通过 PowerShell 自动化 WSUS

我编写了一个脚本,目的是快速管理WSUS进程,我有一些硬编码的东西,但更愿意使用 PowerShell。特别是 Approve-WsusUpdate 的“目标”组。

目前我正在做这样的事情:

#Select Target Group for Update Approval:

$TargetComputerGroups = "All Computers", "Unassigned Computers", "Clients", "Servers", "Test", "View Templates"

$UserPrompt = @"

Please select a Computer Group from the below options:

1) All Computers (Selects all of the below)
2) Unassigned Computers
3) Clients
4) Servers
5) Test
6) View Templates

Enter selection
"@

###Record user selection to varirable
$TargetComputerGroupTemp = Read-Host -Prompt $UserPrompt

###Convert their choice to the correct 0-index array value.
$TargetComputerIndex = …
Run Code Online (Sandbox Code Playgroud)

windows powershell wsus

7
推荐指数
1
解决办法
5856
查看次数

标签 统计

powershell ×2

scripting ×1

windows ×1

wsus ×1