Kyurious Minds Computer Academy Blog Powershell Activities

Powershell Activities

Activity Description
1. Simple Output Use write-host to print “Hello, World!” to the console.
2. User Input Use read-host to prompt the user for their name and then use write-host to greet them.
3. Create a Directory Use mkdir to create a new directory named “Practice”.
4. Copy a File Create a text file named “file.txt” with some content in it, then use copy-item to make a copy of “file.txt” named “file_backup.txt”.
5. Rename a File Use rename-item to rename “file.txt” to “newfile.txt”.
6. Move a File Use move-item to move “file_backup.txt” into the “Practice” directory.
7. List Windows Services Use get-service to retrieve a list of all the services on your computer.
8. Save Service List to File Pipe the output of get-service to out-file and save it as “services.txt”.
9. Custom Output Create a script that prints a formatted list of all services, including their name and status, using get-service and write-host.
10. User Interaction Create a script that asks the user for a file name, copies that file to a backup location, and then confirms the action with a message using read-host, copy-item, and write-host.
11. Directory Creation with User Input Prompt the user to enter a name for a new directory using read-host, then use mkdir to create that directory.
12. File Copy with User Input Ask the user for the name of a file they want to copy and the destination folder using read-host, then use copy-item to copy the file to the specified location.
13. File Renaming with User Input Prompt the user to enter the name of a file they want to rename and the new name using read-host, then use rename-item to rename the file.
14. File Movement with User Input Ask the user for the name of a file they want to move and the destination folder using read-host, then use move-item to move the file to the specified location.
15. Service Status Check with User Input Prompt the user to enter the name of a service they want to check using read-host, then use get-service to retrieve the status of that service and display it.
16. Output File Creation with User Input Ask the user for a message they want to save to a file using read-host, then use out-file to save the message to a file named by the user.
17. User Confirmation Create a script that asks the user if they want to perform a certain action (like deleting a file) using read-host, then execute the action based on their response.
18. Interactive Menu Create a script that presents the user with a menu of options (e.g., create directory, copy file, etc.) using read-host, then execute the selected option.
19. User-Defined Variables Prompt the user to enter values for variables (e.g., file paths, directory names) using read-host, then use those variables in subsequent commands.
20. Error Handling with User Input Create a script that prompts the user for input, but if they enter an invalid value (e.g., a non-existent file name), provide an error message and prompt them again until they enter a valid value. Use try-catch for error handling.
21. Delayed execution Write a script that prompts the user for a time in seconds using read-host, then uses Start-Sleep to delay execution for the specified time before continuing.
22. Filter Services by Status Write a script that prompts the user to enter a service status (e.g., Running, Stopped) using read-host, then uses Get-Service to retrieve a list of services with that status.
23. Display Service Dependencies Write a script that prompts the user for a service name using read-host, then uses Get-Service to retrieve information about that service, including its dependencies.
24. Secure Input Write a script that prompts the user for a password without displaying the input using read-host -AsSecureString, then converts the secure string to plain text for further processing.
25. Create Multiple Files Write a script that prompts the user for a directory path using read-host, then uses New-Item to create multiple files within that directory.
26. Validate File Existence Write a script that prompts the user for a file name using read-host, then checks if the file exists. If the file does not exist, display an error message and prompt the user again.
27. Handle Invalid Input with Retry Limit Write a script that prompts the user for a password using read-host, and allows a maximum of three attempts. If the user fails to provide the correct password within three attempts, display an error message and terminate the script.
28. Text Analysis Prompt the user to input a piece of text and analyze the text to determine the following:
  • Number of words
  • Number of characters
  • Number of lines (if applicable)
  • Display the analysis results.
29. Text Search in multiple files Prompt the user to mention a text and folder path (having multiple files). Find the file that contains that specific text.
Display the file name to the user.
30. Move old files Prompt the user to enter a directory path. Retrieve files in the directory and move files older than a specified number of days to the “archive” folder.