Advertisement
xdxdxd123

Powershell Coursera

Mar 17th, 2018
2,178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.71 KB | None | 0 0
  1. Introduction
  2. In this lab, you'll learn the foundations of how managing user permissions works on a Windows machine. Using the new Powershell commands you learned, you'll fix up the permissions of some files and folders.
  3.  
  4. Head's up: You'll experience a delay as the labs initially load (particularly for Windows labs). So, please wait a couple of minutes for the labs to load. Please also make sure to access the labs directly through Coursera and not in the Qwiklabs catalog. If you access the labs through the Qwiklabs catalog, you will *not* receive a grade. (As you know, a passing grade is required to matriculate through the course.) The grade is calculated when the lab is complete, so be sure to hit "End Lab" when you're done!
  5.  
  6. You'll have 60 minutes to complete this lab.
  7.  
  8. What you'll do
  9.  
  10. In this lab, you'll create and change folder permissions using the Windows Command Line Interface (CLI), known as Powershell. In this exercise, you'll:
  11.  
  12. access administrative privileges to use Powershell in Windows.
  13. view file and folder permissions using the GUI and Powershell commands.
  14. modify the permissions for both files and directories by granting and removing specific permissions using ICACLS in Powershell.
  15. modify the permissions for groups using the GUI and Powershell.
  16. Go ahead and connect to the windows-instance Google Cloud VM now. As a reminder, your machines are available in Google Cloud Console under Compute Engine -> VM instances. If you're having difficulty connecting to your instance, no worries! Just follow the steps outlined in the Accessing Qwiklabs reading for detailed instructions on how to connect.
  17.  
  18. Permissions Using Windows Powershell
  19.  
  20. Powershell is used through the rest of the lab, and you'll need administrative privileges. Open it now by searching for "Powershell" in the start menu, then right-clicking it and selecting "Run as Administrator".
  21.  
  22. Example 1
  23.  
  24. In "C:\Users\Qwiklab\Documents\" you have a file named "important_document." Your goal in this example is to change the permissions so that the user "Kara" only has read access to the file.
  25.  
  26. First, use ICACLS to view the existing permissions for the file using this command:
  27.  
  28. ICACLS C:\Users\Qwiklab\Documents\important_document
  29.  
  30.  
  31. As you can see, Kara currently has read and write permissions (shown as "R" and "W"). We need her to only have read permissions, so we need to remove her write permission. An easy way to accomplish this is to remove all of Kara's permissions and then re-add her read permission. You can remove her entirely from the file's permissions and check to see that it worked with these commands:
  32.  
  33. ICACLS C:\Users\Qwiklab\Documents\important_document /remove "Kara"
  34.  
  35.  
  36. ICACLS C:\Users\Qwiklab\Documents\important_document
  37.  
  38.  
  39. As you can see, Kara is no longer listed in the file's permissions. To re-grant her only the read permission, use this command:
  40.  
  41. ICACLS C:\Users\Qwiklab\Documents\important_document /grant "Kara:(r)"
  42.  
  43.  
  44. Now the file's permissions should be set correctly, with Kara only having read permissions. You can double check this with the earlier command:
  45.  
  46. ICACLS C:\Users\Qwiklab\Documents\important_document
  47.  
  48.  
  49. Example 2
  50.  
  51. There's a folder called "Secret" in "C:\Users\Qwiklab\" where the user "Kara" has read access. Your goal in this example is to alter these permissions so that another user (named "Phoebe") has read permissions as well, and Kara has both read and write permissions. You can view the current permissions with this command, and see that Kara has read permissions and Phoebe is not included.
  52.  
  53. ICACLS C:\Users\Qwiklab\Secret\
  54.  
  55.  
  56. First, give Phoebe read access. You can grant her these permissions with the command below, like before. Then, use the previous command again to verify that the change has been made:
  57.  
  58. ICACLS C:\Users\Qwiklab\Secret\ /grant "Phoebe:(r)"
  59.  
  60.  
  61. ICACLS C:\Users\Qwiklab\Secret\
  62.  
  63.  
  64. The next step is to grant Kara write permissions. You don't need to remove her existing permissions first, like you did before; you only need to add "write" to her existing permissions with this command:
  65.  
  66. ICACLS C:\Users\Qwiklab\Secret\ /grant "Kara:(w)"
  67.  
  68.  
  69. Now the file should have the required permissions. View them to verify this with the following command:
  70.  
  71. ICACLS C:\Users\Qwiklab\Secret\
  72.  
  73.  
  74. Example 3
  75.  
  76. There's another folder in "C:\Users\Qwiklab\" called "Music". The user group, named "Everyone", has both read and write permissions for this folder. User groups are sets of local users that allow you to change multiple users' permissions at once. For example, a computer that's used by lots of employees at a business may have a usergroup called "Employees" that new hires are added to when they onboard. This automatically gives them access to everything they need, without it having to be set manually. The "Everyone" group is created by default, and every new user is automatically added.
  77.  
  78. Your goal for this example is to change the permissions for this folder so that the "Everyone" group only has read permission (not write).
  79.  
  80. As usual, view the current permissions with this command:
  81.  
  82. ICACLS C:\Users\Qwiklab\Music\
  83.  
  84.  
  85. You can change permissions for groups in exactly the same way as you do for users. To remove the group's current permissions, and then re-grant them a read permission, use these commands:
  86.  
  87. ICACLS C:\Users\Qwiklab\Music\ /remove "Everyone"
  88. ICACLS C:\Users\Qwiklab\Music\ /grant "Everyone:(r)"
  89.  
  90.  
  91. The "Everyone" group should now have only read permissions, which you can check using the same command as before:
  92.  
  93. ICACLS C:\Users\Qwiklab\Music\
  94.  
  95.  
  96. Example 4
  97.  
  98. Back in the "documents" folder from before, there's a file called "not_so_important_document". In this example, you need to modify the permissions for that file so that the group called "Authenticated Users" has "Write" access. The "Authenticated Users" group is another automatically created group, containing all users with admin privileges. View the current permissions with this command, to see what the starting point for this file is:
  99.  
  100. ICACLS C:\Users\Qwiklab\Documents\not_so_important_document
  101.  
  102.  
  103. This will show you that the "Authenticated Users" group is currently not listed. This means that the only step required is to grant them write access, which you can do with this command:
  104.  
  105. ICACLS C:\Users\Qwiklab\Documents\not_so_important_document /grant "Authenticated Users:(w)"
  106.  
  107.  
  108. That should successfully grant them write permissions. You can use the same command as earlier to verify that the commands were a success:
  109.  
  110. ICACLS C:\Users\Qwiklab\Documents\not_so_important_document
  111.  
  112.  
  113. Example 5
  114.  
  115. In this final example, you'll change the permissions of another file in the "Documents" folder. The file named "public_document" needs to be made publically readable, so that anyone on the system is able to read it. As usual, view the file's commands first:
  116.  
  117. ICACLS C:\Users\Qwiklab\Documents\public_document
  118.  
  119.  
  120. The easiest way to make sure that all users on the system have read permissions is to add those permissions to the "Everyone" group. You could also add each user manually, but by giving the group the permissions instead, you save time; it removes the need to go back and edit permissions again if a new user is created in the future. Grant every user on the system the ability to read the file using this command:
  121.  
  122. ICACLS C:\Users\Qwiklab\Documents\public_document /grant "Everyone:(r)"
  123.  
  124.  
  125. Finally, view the permissions again to make sure it worked:
  126.  
  127. ICACLS C:\Users\Qwiklab\Documents\public_document
  128.  
  129.  
  130. Conclusion
  131.  
  132. Wohoo! You've successfully used Powershell to modify the permissions for both files and directories. You modified the permissions by granting and removing specific permissions using ICACLS. You've also become familiar with groups of users, and how to modify permissions for them as well. Really well done.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement