Powershell - compilation with modules

I created a log-on script based on the Active Directory module, which requests membership in a user group to display its drives, etc.

I compiled it with PowerGui and created an EXE file. the problem is that the module does not exist on users' computers.

Is there a way to do this without a module or add a module to compilation?

+5
source share
2 answers

For group membership, you can also get it without connecting to AD and analyze the output of the WHOAMI utility

$groups = WHOAMI /GROUPS /FO CSV | ConvertFrom-Csv | Select-Object -ExpandProperty 'Group Name'

if($groups -contains 'group1')
{
   do something
}
+2
source

One way is to use the Active Directory Service Interface (ADSI) .

SO ( ?), , , ADSI, #, .

.

Clear-Host
$dn = New-Object System.DirectoryServices.DirectoryEntry ("LDAP://WM2008R2ENT:389/dc=dom,dc=fr","jpb@dom.fr","Pwd")

# Look for a user
$user2Find = "user1"
$Rech = new-object System.DirectoryServices.DirectorySearcher($dn)
$rc = $Rech.filter = "((sAMAccountName=$user2Find))"
$rc = $Rech.SearchScope = "subtree"
$rc = $Rech.PropertiesToLoad.Add("mail");

$theUser = $Rech.FindOne()
if ($theUser -ne $null)
{
  Write-Host $theUser.Properties["mail"]
} 

- System.DirectoryServices.AccountManagement Namespace.

ADSI, , Framework.NET 3.5. , Edited (2011-10-18 13:25), #, .

WMI:

$user2Find = "user1"
$query = "SELECT * FROM ds_user where ds_sAMAccountName='$user2find'"
$user = Get-WmiObject -Query $query -Namespace "root\Directory\LDAP"
$user.DS_mail

, WMI .

+1

All Articles