How to find what to use, understanding logic.

Hi, i am newbie in powerhsell. And i want to understand scripts , how they constructed. Where writer found what to add which methods use and so on. For example:
Below there is System.Security.AccessControl.FileSystemAccessRule. I want to know how writer of this script find which class to use, where to find logic how to use classes.

$ACL = Get-ACL C:\Test
$AccessRule = new-object System.Security.AccessControl.FileSystemAccessRule ("TestUser","Modify","Allow")
$ACL | Set-Acl C:\Test

I think the key is Yoda level skills of Googling. “file permissions dot net”

Well, logic would be be

get-acl c:\temp
$acl = get-acl c:\temp
$acl | select *
$acl | get-member

then you need to figure out how to create new rule. You can use that

$AccessRule = new-object System.Security.AccessControl.FileSystemAccessRule (“TestUser”,“Modify”,“Allow”)

$AccessRule = $acl.access | where {$_.IdentityReference -eq “TestUser”}

And then you pop up back to the methods you found using Get-Member. First remove the desired access from the access list object and last set new, modified, ACL to the object

$ACL | Set-Acl C:\Temp

In my opinion, there is two ways to learn. Either go to some basic powershell courses where is they go through pipepline and get-member or start googling and digging and turning all the stones.

I did the latter one, and it has taken quite a lot of time, but I’ve learned bunch of stuff on this path


In general get-help is good for whatever you want to search/find more info on. I find there are some good get-help about_… files in PowerShell as well. Hopefully this helps.

For info on .Net classes you may want to search on MSDN. Not really Powershell but it can help to understand stuff like expected parameters, available methods, …

I would highly recommend 2 books. You do need to understand the basics first and these are great tools not only for learning but for reference later on. These are written by Don Jones and Jeffrey D. Hicks and you will find they are absolutely invaluable.

Learn Windows PowerShell in a month of lunches (This one first)
Learn PowerShell Toolmaking in a month of lunches

Get-Help, Get-Member, and Get-Command are the best 3 self-discovery commands. For more detail you can google “how can I do X in PowerShell” – there are plenty of blog posts and such around which are great resources. Not all of them have fantastic code style, but they’ll get you what you need and you can adjust as you need to.

My PSKoans module may also help you out. :slight_smile: