Posts

Showing posts from July, 2021

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                 Group = $group                 Member = 'True'             }         }         else{             [PSCustomObject]@{                 Name = $user                 Group = $group                 Member = 'False'             }         }     } }   $result #| export-csv "c:\result.csv" -NoTypeInformation

DHCP - Report for all DHCP scopes with detail

Script for DHCP scope report: $DHCP_Scopes = Get-DhcpServerv4Scope –ComputerName   FQDN   -ErrorAction Stop             #$DHCP_Scopes = $Null     $output = Foreach ( $DHCP_Scope in $DHCP_Scopes ) {         # Going through the scopes returned in a given server         $DHCP_Scope_Stats = Get-DhcpServerv4ScopeStatistics -ComputerName   FQDN   -ScopeId $DHCP_Scope . ScopeId         [ PSCustomObject ] @{             'DHCP Server'     = $DHCP_Server . DNSName             'DHCP IP'         = $DHCP_Server . IPAddress             'Scope ID'        = $DHCP_Scope . ScopeId . IPAddressToString             'Scope Name'      = $DHCP_Scope . Name             'Scope State'     = $DHCP_Scope . State             'In Use'          = $DHCP_Scope_Stats . InUse             'Free'            = $DHCP_Scope_Stats . Free             '% In Use'        = ( [ math ]:: Round( $DHCP_Scope_Stats . Percen

Users - Move multiple users to mutiple OU from CSV file

Below script can use to move multiple users to mutiple OU from CSV file. #Import AD Module Import-Module ActiveDirectory $Imported = Import-Csv -Path "C:\Users\Administrator\Desktop\Move.csv" $Imported | ForEach-Object { $SamAccountName = $_.SamAccountName Enable-ADAccount -Identity $SamAccountName # Retrieve DN of User. $UserDN = (Get-ADUser -Identity $_.SamAccountName).distinguishedName $TargetOU = $_.TargetOU Write-Host " Moving Accounts ..... " # Move user to target OU. Move-ADObject -Identity $UserDN -TargetPath $TargetOU } Write-Host " Completed move " $total = ($Imported).count Write-Host $total "User Moved Successfully"