Mapeamento Caminho de Rede (VBSCRIPT) por Grupo do Active Directory

Existe alguns casos em que é necessário criar um VBSCRIPT para mapear a unidade de rede com base nos grupos aos quais o usuário pertence, desta forma mapeando o caminho da pasta da Diretoria ou Área da qual o mesmo pertence. Consultando assim os grupos dos quais o usuário pertence no Active Directory.

Neste caso elaborei um script em vbscript que posteriormente pode ser aprimorado por qualquer um, não sou um expert em script.

Este vbscript pode ser colocado numa Política de Grupo (GPO) através de script de Logon:

Segue abaixo script:

Set objSysInfo = CreateObject(“ADSystemInfo”)
Set objNetwork = CreateObject(“Wscript.Network”)

strUserPath = “LXXP://” & objSysInfo.UserName
Set objUser = GetObject(strUserPath)

‘********************************************

objMemberOf = objUser.GetEx(“MemberOf”)

For Each strGroup in objMemberOf
strGroupPath = “LXXP://” & strGroup
Set objGroup = GetObject(strGroupPath)
strGroupName = objGroup.CN

Set net = createobject(“wscript.network”)
Set FSODrive= CreateObject(“Scripting.FileSystemObject”)

‘**********************************************
‘ Mapeamento Pasta Publica
‘**********************************************

‘Pasta Publica (Transferência)

If Not FSODrive.DriveExists(“Z:”) Then
objNetwork.MapNetworkDrive “Z:”, “\\caminhoderede\PUBLICA”, False
Else
objNetwork.RemoveNetworkDrive “Z:”, True, True
objNetwork.MapNetworkDrive “Z:”, “\\caminhoderede\PUBLICA”, False
End If

‘**********************************************
‘Diretoria XX
‘**********************************************
Select Case strGroupName

Case “ACESSO XX – LISTAR”
‘Pasta Diretoria
If Not FSODrive.DriveExists(“X:”) Then
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
Else
objNetwork.RemoveNetworkDrive “X:”, True, True
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
End If

Case “XX”
‘Pasta Diretoria
If Not FSODrive.DriveExists(“X:”) Then
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
Else
objNetwork.RemoveNetworkDrive “X”, True, True
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
End If

Case “XX_LP”
If Not FSODrive.DriveExists(“X:”) Then
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
Else
objNetwork.RemoveNetworkDrive “X”, True, True
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
End If

‘**********************************************
‘Diretoria XX
‘**********************************************

Case “ACESSO XX – LISTAR”
‘Pasta Diretoria
If Not FSODrive.DriveExists(“X:”) Then
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
Else
objNetwork.RemoveNetworkDrive “X:”, True, True
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
End If

Case “XX”
‘Pasta Diretoria
If Not FSODrive.DriveExists(“X:”) Then
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
Else
objNetwork.RemoveNetworkDrive “X”, True, True
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
End If

Case “XX_LP”
If Not FSODrive.DriveExists(“X:”) Then
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
Else
objNetwork.RemoveNetworkDrive “X:”, True, True
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
End If

‘**********************************************
‘Diretoria XX
‘**********************************************

Case “ACESSO XX – LISTAR”
‘Pasta Diretoria
If Not FSODrive.DriveExists(“X:”) Then
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
Else
objNetwork.RemoveNetworkDrive “X:”, True, True
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
End If

Case “XX”
‘Pasta Diretoria
If Not FSODrive.DriveExists(“X:”) Then
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
Else
objNetwork.RemoveNetworkDrive “X”, True, True
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
End If

Case “XX_LP”
If Not FSODrive.DriveExists(“X:”) Then
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
Else
objNetwork.RemoveNetworkDrive “X:”, True, True
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
End If

‘**********************************************
‘Diretoria XX
‘**********************************************

Case “ACESSO XX_XX – LISTAR”
‘Pasta Diretoria
If Not FSODrive.DriveExists(“X:”) Then
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX\XX”, False
Else
objNetwork.RemoveNetworkDrive “X:”, True, True
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX\XX”, False
End If

Case “XX_XX_LP”
‘Pasta Diretoria
If Not FSODrive.DriveExists(“X:”) Then
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX\XX”, False
Else
objNetwork.RemoveNetworkDrive “X:”, True, True
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX\XX”, False
End If

‘**********************************************
‘Diretoria DO
‘**********************************************

Case “ACESSO DO – LISTAR”
‘Pasta Diretoria
If Not FSODrive.DriveExists(“X:”) Then
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\DO”, False
Else
objNetwork.RemoveNetworkDrive “X:”, True, True
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\DO”, False
End If

Case “DO”
‘Pasta Diretoria
If Not FSODrive.DriveExists(“X:”) Then
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\DO”, False
Else
objNetwork.RemoveNetworkDrive “X:”, True, True
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\DO”, False
End If

Case “DO_LP”
If Not FSODrive.DriveExists(“X:”) Then
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\DO”, False
Else
objNetwork.RemoveNetworkDrive “X:”, True, True
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\DO”, False
End If

‘**********************************************
‘Diretoria XX
‘**********************************************

Case “ACESSO XX – LISTAR”
‘Pasta Diretoria
If Not FSODrive.DriveExists(“X:”) Then
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
Else
objNetwork.RemoveNetworkDrive “X:”, True, True
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
End If

Case “XX”
‘Pasta Diretoria
If Not FSODrive.DriveExists(“X:”) Then
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
Else
objNetwork.RemoveNetworkDrive “X:”, True, True
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
End If

Case “XX_LP”
If Not FSODrive.DriveExists(“X:”) Then
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
Else
objNetwork.RemoveNetworkDrive “X:”, True, True
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
End If

‘**********************************************
‘Diretoria XX
‘**********************************************

Case “ACESSO XX – LISTAR”
‘Pasta Diretoria
If Not FSODrive.DriveExists(“X:”) Then
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
Else
objNetwork.RemoveNetworkDrive “X:”, True, True
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
End If

Case “XX”
‘Pasta Diretoria
If Not FSODrive.DriveExists(“X:”) Then
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
Else
objNetwork.RemoveNetworkDrive “X:”, True, True
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
End If

Case “XX_LP”
If Not FSODrive.DriveExists(“X:”) Then
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
Else
objNetwork.RemoveNetworkDrive “X:”, True, True
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
End If

‘**********************************************
‘Diretoria XX
‘**********************************************

Case “ACESSO XX – LISTAR”
‘Pasta Diretoria
If Not FSODrive.DriveExists(“X:”) Then
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
Else
objNetwork.RemoveNetworkDrive “X:”, True, True
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
End If

Case “XX”
‘Pasta Diretoria
If Not FSODrive.DriveExists(“X:”) Then
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
Else
objNetwork.RemoveNetworkDrive “X:”, True, True
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, True
End If

Case “XX_LP”
If Not FSODrive.DriveExists(“X:”) Then
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
Else
objNetwork.RemoveNetworkDrive “X:”, True, True
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
End If

‘**********************************************
‘Diretoria XX
‘**********************************************

Case “ACESSO XX – LISTAR”
‘Pasta Diretoria
If Not FSODrive.DriveExists(“X:”) Then
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
Else
objNetwork.RemoveNetworkDrive “X:”, True, True
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
End If

Case “XX”
‘Pasta Diretoria
If Not FSODrive.DriveExists(“X:”) Then
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
Else
objNetwork.RemoveNetworkDrive “X:”, True, True
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
End If

Case “XX_LP”
If Not FSODrive.DriveExists(“X:”) Then
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
Else
objNetwork.RemoveNetworkDrive “X:”, True, True
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
End If

‘**********************************************
‘Diretoria XX
‘**********************************************

Case “ACESSO XX – LISTAR”
‘Pasta Diretoria
If Not FSODrive.DriveExists(“X:”) Then
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
Else
objNetwork.RemoveNetworkDrive “X:”, True, True
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
End If

Case “XX”
‘Pasta Diretoria
If Not FSODrive.DriveExists(“X:”) Then
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
Else
objNetwork.RemoveNetworkDrive “X:”, True, True
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
End If

Case “XX_LP”
If Not FSODrive.DriveExists(“X:”) Then
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
Else
objNetwork.RemoveNetworkDrive “X:”, True, True
objNetwork.MapNetworkDrive “X:”, “\\caminhoderede\XX”, False
End If

End Select
Next

Espero que Tenha ajudado.

Até mais.

Anúncios

Deixe um comentário

Preencha os seus dados abaixo ou clique em um ícone para log in:

Logotipo do WordPress.com

Você está comentando utilizando sua conta WordPress.com. Sair / Alterar )

Imagem do Twitter

Você está comentando utilizando sua conta Twitter. Sair / Alterar )

Foto do Facebook

Você está comentando utilizando sua conta Facebook. Sair / Alterar )

Foto do Google+

Você está comentando utilizando sua conta Google+. Sair / Alterar )

Conectando a %s