I'm writing an AD Termination script for work. I'm new to PowerShell and was wondering if multiple commands within PowerShell switch statement is okay to do:
# Switch statement to start here
$switchTitle = "Terminate User"
$confirmMessage = "Are you sure that " + $fullName + " is the user that you want to terminate?"
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes",
"Starts the termination process for the selected user"
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No",
"Cancels the termination process and, eventually, will prompt for another user selection"
$options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)
$result = $host.ui.PromptForChoice($switchTitle, $confirmMessage, $options, 0)
switch ($result)
{
0 {"You have selected Yes. The Termination Script will now start."
Copy-Item -Path "Microsoft.PowerShell.Core\FileSystem::\\Path\To\UserFolder" `
-Destination "Microsoft.PowerShell.Core\FileSystem::\\path\To\TermFolder" -Recurse -Force
# TODO: Put delete command here for old profile
# TODO: Put Disable AD Object command here
}
1 {"You have selected No. Please choose another user."}
}
I'm also concerned with PowerShell styling/conventions so if I'm doing anything wrong, please let me know.