Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for login_connect_network_drives_based_on_group_membership.ps

(view source code of login_connect_network_drives_based_on_group_membership.ps as plain text)

  1. # Local group
  2. # Source: https://morgantechspace.com/2017/10/check-if-user-is-member-of-local-group-powershell.html
  3. $groupObj = [ADSI]"WinNT://./Administrators,group"
  4. $membersObj = @( $groupObj.psbase.Invoke( "Members" ) )
  5. $members = ( $membersObj | ForEach-Object { $_.GetType( ).InvokeMember( 'Name', 'GetProperty', $null, $_, $null ) } )
  6. If ( $members -contains $Env:UserName ) {
  7. 	New-SmbMapping -LocalPath 'T:' -RemotePath "\\CompanyServer\AdminTools"
  8. }
  9.  
  10. # AD group, use "Import-Module ActiveDirectory" once
  11. # Source: https://morgantechspace.com/2015/07/powershell-check-if-ad-user-is-member-of-group.html
  12. $members = Get-ADGroupMember -Identity 'Marketing' -Recursive | Select -ExpandProperty Name
  13. If ( $members -contains $Env:UserName ) {
  14. 	New-SmbMapping -LocalPath 'M:' -RemotePath "\\CompanyServer\Marketing"
  15. }

page last uploaded: 2021-01-27, 16:12