Super Simple Scripts

DISCLAIMER: This was originally a way to document what I was learning when I first ran into PowerShell as a student who had no prior scripting experience. The examples given and the posts done in relation to the project most likely do not follow best practices and should definitely be reviewed if they are going to be used in any fashion. You have been warned! 🙂

Here you will find all of the Super Simple Scripts made throughout The PowerShell Project.

Super Simple Script I
Referenced in A Better Basics Rundown

# Searches directory/subdirectories for specific file types then copies to destination
$filesrce = Read-Host "Enter Directory to Search"
$filedest = Read-Host "Extract Files Here"
$filetype = Read-Host "File Type to Search For (examples are avi, pdf, txt)"
ls $filesrce -recurse -include *.$filetype | cp -destination $filedest

Super Simple Script II
Referenced in ISE, ExecutionPolicy, and Popup

# First line calls the ingredients for a GUI “form” 
# Making a popup based on the user-defined variable 
$wat =Read-Host “Type something here”  
[System.Windows.Forms.MessageBox]::Show(“You typed '$wat' and this box is showing you stuff.”, “Awesome”)

Super Simple Script III
Referenced in Active Directory Power

# Prompt user to enter the ADUser, and add them to an ADGroup
Import-Module ActiveDirectory [System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”) $dagroup = Read-Host “What group are we adding to”
$dauser = Read-Host “What user are we adding to $dagroup”
Add-ADGroupMember $dagroup $dauser [System.Windows.Forms.MessageBox]::Show(“$dauser was added to $dagroup”, “Done”)

Super Simple Script IV
Referenced in Future of The PowerShell Project and Learning Python

# Enter a username; receive actual Last/First name and group membership
Import-Module ActiveDirectory
$thatdude = Read-Host “So who ya lookin’ for?”
$thisdude = Get-ADuser $thatdude
$firstname = $thatdude.givenname
$lastname = $thatdude.surname
$fullname = “$lastname,$firstname”
$groups = Get-ADPrincipleGroupMembership $thatdude | ft Name
$fullname >> Info.txt
$groups >> Info.txt
“” >> Info.txt
notepad ./Info.txt

Super Simple Script V
Referenced in Super Simple Script V

# Bring on the AD cmdlets
Import-Module activedirectory
# Prompt the user for a group to extract info from
$userlist = Read-Host “What ADGroup would you like to extract users/email-addresses from?”
# Gather user objects from $userlist
$users = Get-ADGroupMember $userlist
# Foreach user object in $users 
Foreach ($user in $users) {
  (Get-ADUser $user).Name + ” ” + (Get-ADUser $user -Properties mail).mail >> emailList.txt
} # Open notepad with the results at script end
notepad emailList.txt


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s