none
Question about a code line in PowerShell. RRS feed

  • Question

  • I have experience adminsitering Active Directory from the GUI.  Now I am teaching myself PowerShell so I can work with AD from the command line/scripts.  I understand this set of commands and it's net result.  However, I am wondering what the purpose of the initial line )"set-alias no new-object").  I understand the Aet-Alias and New-Object cmdlets, but have no idea what the "no" is for.  Any explanation would be appreciated.

        Also, why is there a "no" in the line $r=no system.security.AcessControl.filesystemaccessrule $perm, when the new permission is added to the access control object?  Again I understand the overall functioning of the code set, but have no idea why the "no" is there.  Again, any assistance would be appreciated.

    set-alias no new-object

    $acl = get-acl c:\logs
    $perm = "room5\test","fullcontrol","allow"
    $r = no system.security.accesscontrol.filesystemaccessrule $perm
    $acl.addaccessrule($r)

    $resc = gci c:\logs -recurse -force 
    foreach($f in $resc) { 

      write-host $f.fullname
      $acl | set-acl $f.FullName
    }

    Saturday, July 8, 2017 1:06 AM

Answers

  • Hello!

    I think on the first line, you are setting "no" as an alias for the cmdlet "New-Object".

    For your second question, you are using the "no" alias that you created on the first line to create an object.

    You can learn more about the Set-Alias cmdlet at https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.utility/set-alias

    • Marked as answer by Technician7 Saturday, July 8, 2017 7:32 PM
    Saturday, July 8, 2017 1:57 AM

All replies

  • Hello!

    I think on the first line, you are setting "no" as an alias for the cmdlet "New-Object".

    For your second question, you are using the "no" alias that you created on the first line to create an object.

    You can learn more about the Set-Alias cmdlet at https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.utility/set-alias

    • Marked as answer by Technician7 Saturday, July 8, 2017 7:32 PM
    Saturday, July 8, 2017 1:57 AM
  • GREAT!  THANKS!  This makes sense.  
    Saturday, July 8, 2017 7:32 PM