我过去创建了一个 PS 脚本,我希望它更具交互性。
这是我创建的脚本。
$csv = Import-CSV 'C:\Users\w0vlnd\Desktop\Powershells\Computers in a specific workgroup or domain.csv'
$ADprops = @(
'DisplayName'
'Mail'
'LastBadPasswordAttempt'
'AccountExpirationDate'
'PasswordLastSet'
'Enabled'
)
$filter = @(
$ADprops
@{
Name = 'Account active'
Expression = {$Account}
}, @{
Name = 'Password Changeable'
Expression = { $changeable }
}, @{
Name = 'Password Expires'
Expression = { $expires }
}, @{
Name = 'Last logon'
Expression = { $lastlogon }
}, @{
Name = 'PC Name'
Expression = { $pcName }
}, @{
Name = 'System Boot Time'
Expression = { $Boot }
}
)
Clear-Host
do
{
Write-Host "Enter the user ID: " -ForegroundColor Cyan -NoNewline
$UserName = Read-Host
Write-Host ""
#Computer Info#
$pcName = $csv.Where({ $_."User ID" -match $Username })."PC Name"
$boot = SystemInfo /s $pcName | Select-String -Pattern 'System Boot Time'|
ForEach-Object { ($_ -split '\s{2,}')[1] }
#Account and passowrd information#
$Account, $expires, $changeable, $lastlogon = net user $Username /domain |
Select-String -Pattern 'Account active|Password Changeable|Password Expires|Last logon'|
ForEach-Object { ($_ -split '\s{2,}')[1] }
Get-ADUser -Identity $Username -Properties $ADprops |
Select-Object $filter
} while ($Username -notcontains $Processes)
我想把它放到这个脚本中,但我正在弄清楚如何做。与第一个脚本一样,用户必须首先填写用户 ID。之后他应该得到选项 U,P,... 每个选项都应该执行一个命令。您可以在第一个脚本中找到哪个命令的示例,例如:#computer info# 如果我已经运行了一个命令,我将自己解决其余的问题。我怎样才能做到这一点?选择该选项后,菜单也应返回。
提前致谢!
param (
[string]$Title = 'UserInfo V3.1'
)
Clear-Host
Write-Host "================ $Title ================"
Write-Host "Press 'U' for general user info."
Write-Host "Press 'P' for account and password information."
Write-Host "Press 'C' computer information."
Write-Host "Press 'G' group memberships."
Write-Host "Press 'R' search for other user ID."
Write-Host "Press 'Q' to Quit."
}
Show-Menu –Title 'UserInfo V3.1'
$selection = Read-Host "Please make a selection"
switch ($selection)
{
'U' {
'You chose option #U'
} 'P' {
'You chose option #P'
} 'C' {
'You chose option #C'
} 'G' {
'You chose option #G'
} 'Q' {
'You chose option #Q'
return
}