I've created a PS script in the past and I would like it to be more interactive.
This is the script I've created.
$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)
And I want to put it in to this script but I'm figuring out how. As in the first script the user must first fill in the user ID. Afterwards he get should get the options U,P,... Each option should be executing a command. An example of which command you can find in the first script like: #computer info# IF I haver already one command running I'll figure the rest out myself. How can I do this? Also the menu should come back after the option has been chosen.
Thanks in advance!
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
}