Posts

Powershell: Remove multiple users from a single AD group

 Remove multiple users from a single AD group https://www.powershellbros.com/remove-user-from-specifc-ad-groups-using-powershell/ Start-Transcript -Path C:\Temp\Remove-ADUsers.log -Append #Taking AD group member detail and will send them by Mail. #Getting AD group member detail and save in CSV format. (Get-ADGroup " AD-Group-Name " -properties members).members | Get-ADUser -properties displayName | Select-Object displayName,SamAccountName,emailaddress | export-CSV c:\users\administrator\ AD-Group-Name (or File-Name) .csv #Import the user list $Users = Import-Csv " C:\Temp\ Users.csv " #Update the AD group name which is need to be removed for listed users. $Group = “ AD-Group-Name ” $Report = @() foreach ($User in $Users) {     $UPN = $User.UserPrincipalName     $ADUser = Get-ADUser -Filter "UserPrincipalName -eq '$UPN'" | Select-Object SamAccountName         $ExistingGroups = Get-ADPrincipalGroupMembership $ADUser.SamAccountName | Select-Obje...

Event ID 1203 - check the ACL size for the object/s

 Event ID 1203 - check the ACL size for the object/s mentioned in the event ID.

DNS IP change

  $ComputerName = get-content " $env:USERPROFILE \desktop\servers.txt" $report = @() foreach ( $Computer in $ComputerName ) {               $Networks = Get-WmiObject -Class "win32_networkadapterconfiguration" -ComputerName $Computer      }    foreach ( $Network in $Networks ) {     $IPAddress   = $Network . IpAddress [ 0 ]     $SubnetMask   = $Network . IPSubnet [ 0 ]     $DefaultGateway = $Network . DefaultIPGateway     $DNSServers   = $Network . DNSServerSearchOrder             $MACAddress   = $Network . MACAddress       $OutputObj   = New-Object -Type PSObject     $OutputObj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $Computer . ToUpper(...

Homepath profile path set permission

  $csv = Import-Csv -Path "$env:userprofile\desktop\KDrivePath.csv"  ForEach ($item In $csv) {     $acl = Get-Acl $item.Path     $AddPerm = New-Object System.Security.AccessControl.FileSystemAccessRule($item.GroupName,"FullControl","ContainerInherit, ObjectInherit", "None","Allow")      $acl.SetAccessRule($AddPerm)     $acl | Set-Acl $item.Path     Write-Host -ForegroundColor Green "Group $($item.GroupName) created!" }

DHCP - Report with DHCP scope option

  $ListofScopesandTheirOptions = $Null $PrimaryDHCPServer = "s217124rgvw210" $Scopes = Get-DhcpServerv4Scope -ComputerName $PrimaryDHCPServer #For all scopes in the primary server, get the scope options and add them to $LIstofSCopesandTheirOptions foreach ($Scope in $Scopes) { $LIstofSCopesandTheirOptions += Get-DHCPServerv4OptionValue -ComputerName $PrimaryDHCPServer -ScopeID $Scope.ScopeId |select @{label=”DHCPServer”; Expression= {$PrimaryDHCPServer}},@{label=”ScopeID”; Expression= {$Scope.ScopeId}},@{label=”ScopeName”; Expression= {$Scope.Name}},* }

User - Get user name from SID value

 Get user name from SID value $sid = ‘SID-VALUE’ Get-ADObject –IncludeDeletedObjects -Filter "objectSid -eq '$sid'" | Select-Object name, objectClass Refer: Thanks to http://woshub.com/hot-to-convert-sid-to-username-and-vice-versa/

GROUP - Report for list of users from list of AD groups

 Report for list of users from list of AD groups: $users = Get-content c:\user.txt $groups = Get-Content c:\Groups.txt   $result = foreach($user in $userlist){     foreach($group in $grouplist){         try{             $groupmembers = Get-ADGroupMember $group -ErrorAction Stop         }         catch{             $groupmembers = $null         }            if($groupmembers.samaccountname -match $user){             [PSCustomObject]@{                 Name = $user         ...