How to find what to use, understanding logic.

Welcome Forums General PowerShell Q&A How to find what to use, understanding logic.

Viewing 5 reply threads
  • Author
    • #179226
      Topics: 1
      Replies: 0
      Points: 15
      Rank: Member

      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
    • #179247
      Topics: 5
      Replies: 105
      Points: 264
      Helping Hand
      Rank: Contributor

      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


    • #179262
      Topics: 2
      Replies: 5
      Points: 49
      Rank: Member

      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.

    • #179331
      Topics: 1
      Replies: 20
      Points: 57
      Helping Hand
      Rank: Member

      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, ...

    • #179334
      Topics: 28
      Replies: 44
      Points: 165
      Rank: Participant

      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

    • #179355
      Topics: 2
      Replies: 511
      Points: 1,307
      Helping Hand
      Rank: Community Hero

      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. 🙂

Viewing 5 reply threads
  • The topic ‘How to find what to use, understanding logic.’ is closed to new replies.