Showing posts with label Active Directory. Show all posts
Showing posts with label Active Directory. Show all posts

Thursday, February 2, 2023

Powershell: AD DHCP scope information

Needed a script to export dhcp scope and scope id for a domain.


  
  $report = @()
  $DHCPServer = DHCPServerHostname
  $scopes =Get-DhcpServerv4Scope -ComputerName $DHCPServer
  
  foreach ($scope in $Scopes){
    $scopeID = $scope.ScopeId
    $report += Get-DhcpServerv4OptionValue -ScopeId $scopeID -ComputerName $DHCPServer |`
    select @{name="ScopeID";e={$scopeID}},OptionID,Name,Type,@{Name="Value";e={$_.value -join ";"}
  }
    
    $report | export-csv -NoTypeInformation -path "c:\temp\DHCPScopeIDwithOption.csv"
    $scopes | export-csv -NoTypeInformation -path "c:\temp\DHCPScopeIDwithMask.csv"

Wednesday, June 5, 2019

Powershell : Function to get FSMO Info for a domain

function Get-DomainFSMO 
{
[CmdletBinding()]
 [OutputType([System.Management.ManagementObject])]
 param
    (
     [parameter( Mandatory=$false,
                    ValueFromPipeline=$True,
                    Position = 0,
                    HelpMessage="An array of domains.", 
                 ValueFromPipelineByPropertyName=$True)]
     [String[]] $domain
    )
    begin{Write-Verbose "Getting Forest info for: $CurrentDomain"}
    process{
        foreach ($CurrentDomain in $domain){

          $dom = @{
                                label="Domain"
                                expression = {$CurrentDomain}
                            }
         
                
         Write-Verbose "Getting Forest info for: $CurrentDomain"
         Get-ADDomain -Server $CurrentDomain | Select-Object $dom,InfrastructureMaster, RIDMaster, PDCEmulator,DomainMode,DomainSid
         
  
    }
    }
    end{}
 
}

Tuesday, September 6, 2011

Managing AD objects

3 Ways to Move AD Objects
1. Open ADUC and drag and drop object
2. Context Menu - right click
3. DSMove - Command line

Example
To move user tunger from the users container to the sales users ou under corp users ou here is the command
dsmove "cn=tunger,cn=users,dc=tonyunger,dc=com" -newparent "ou=sales users,ou=corp users,dc=tonyunger,dc=com"

3 Ways to Delete Objects
1. Highlight object and hit delete button on keyboard
2. context Menu - right click and choose delete
3. DSRM - command line

Delete User:
DSRM "cn=tunger,cn=users,dc=tonyunger,dc=com"
Delete OU:

Remove an ou named sales users and all objects under the ou
DSRM -subtree - nopromp -c "ou=sales users,ou=corp users,dc=tonyunger,dc=com"
To remove all objects under an OU named sales, but leave the ou intact
DSRM - subtree -exclude -noprompt -c "ou=sales users,ou=corp users,dc=tonyunger,dc=com"

Add a user
dsadd user "cn=tunger,cn=users,dc=tonyunger,dc=com" -fn Tony -ln Unger -pwd 1234 -mustchpwd yes

Monday, September 5, 2011

Active Directory Service command-line tools

High overview

dsadd adding objects.
dsget displaying objects.
dsmod modifying objects.
dsmove moving objects.
dsquery finding objects matching search criteria.
dsrm deleting objects.

Powershell: Microsoft Graph to add new roles to application registration

PowerShell Script Bulk add new roles to application registration in azure. Update $roles with ,Us...