Add-ADGroupMember -Identity 'New Group' -Members (Get-ADGroupMember -Identity 'Old Group' -Recursive)
Tag Archives: AD
Söka efter inloggningar i säkerhetsloggen
För att hitta inloggningar från Administrator på lokal dator.
Get-WinEvent -LogName Security -FilterXPath "*[System[EventID=4624 and TimeCreated[timediff(@SystemTime) <= 86400000]] and EventData[Data[@Name='TargetUserName']='Administrator']]"
För mer info kör | select *
Get-WinEvent -LogName Security -FilterXPath "*[System[EventID=4624 and TimeCreated[timediff(@SystemTime) <= 86400000]] and EventData[Data[@Name='TargetUserName']='Administrator']]" | select *
Skriva ut lista på användare och manager
Skapar en lista med användare under ett givet OU där Managers UserprincipalName är utskrivet.
Get-ADUser -filter * -SearchBase "OU=Users,OU=Administration,OU=Organisation1,DC=intra,DC=contoso,DC=com" -searchscop "onelevel" -properties * | Select CanonicalName,GivenName,Surname,Titel,Department,physicalDeliveryOfficeName,@{N='Manager';E={(Get-ADUser $_.Manager).UserPrincipalName}} | Export-Csv -Encoding utf8 -NoClobber -NoTypeInformation filnamne.csv
Lista hemkatalog och inloggningsscript
Skapa en CSV fil med inloggningsnamn, inloggningsscript och home.
Get-ADUser -filter * -searchbase "ou=business Units,DC=domain,DC=net" -Properties scriptpath,homedirectory,homedrive | select Name, Scriptpath, Homedrive, Homedirectory | Export-Csv C:\temp\users.txt -Encoding utf8
Ställa in homeMTA
För att hitta användare som saknar homeMTA:
Get-ADUser -Filter {(msExchHomeServerName -like "/o=organisation/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Configuration/cn=Servers/cn=servernamn*") -and (homeMTA -notlike "*") -and (msexchrecipienttypedetails -eq "1")}
MSexchrecipienttypedetails = 1 är för vanliga usermailboxes.
För andra värden se http://www.msexchange.org/kbase/ExchangeServerTips/MicrosoftOffice365/ExchangeOnline/msexchangerecipienttypedetails-active-directory-values.html
För att skriva ett värde använd:
$users = Get-ADUser -Filter {(msExchHomeServerName -like "/o=organisation/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Configuration/cn=Servers/cn=Server0*") -and (homeMTA -notlike "*") -and (msexchrecipienttypedetails -eq "1")}
foreach ($user in $users)
{set-ADUser -identity $user -add @{homeMTA="CN=Microsoft MTA,CN=server,CN=Servers,CN=Exchange Administrative Group (FYDIBOHF23SPDLT),CN=Administrative Groups,CN=organisaton,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=contoso,DC=com"}}
Hitta lastlogon AD
Import-Module ActiveDirectory
function Get-ADUserLastLogon([string]$userName)
{
$dcs = Get-ADDomainController -Filter {Name -like "*"}
$time = 0
foreach($dc in $dcs)
{
$hostname = $dc.HostName
$user = Get-ADUser $userName | Get-ADObject -Properties lastLogon
if($user.LastLogon -gt $time)
{
$time = $user.LastLogon
}
}
$dt = [DateTime]::FromFileTime($time)
Write-Host $username "last logged on at:" $dt }
Döp till Get-ADUserLastLogon.ps1
För att köra använd:
Get-ADUserLastLogon -UserName användarnamn
WSUS kommandon
wuauclt /detectnow
wuauclt /resetauthorization /detectnow
wuauclt /reportnow
Sätta AdminDescription
Hitta användare med en viss AdminDescription satt..
Get-ADUser -SearchBase "ou=elev,ou=Users,ou=skola,ou=contoso,DC=us,DC=contoso,DC=com" -filter {admindescription -like "Student"} -properties admindescription | select-object name, admindescription
Sätta AdminDescription..
Get-ADUser -SearchBase "ou=elev,ou=Users,ou=skola,ou=contoso,DC=us,DC=contoso,DC=com" -filter {admindescription -notlike "*"} -properties admindescription | set-aduser -add @{"admindescription"="Student"}
Script för att byta lösenord på användare från CSV fil
# Script to reset Userspassword.
# Use CSV file headers Loginname
param ([string] $CSVPath)
$CSVUsers= (Import-Csv $CSVPath)
$Password = Read-Host "Enter Password" -AsSecureString
ForEach ( $CSVUser in $CSVUsers )
{
Set-ADAccountPassword -identity $CSVUser.loginname -Reset -NewPassword $Password
Set-ADuser -identity $CSVUser.loginname -ChangePasswordAtLogon $true
}
Windows BPA AD DS “Access this computer from the network”
Om man får felmeddelandet “The Active Directory Domain Services Best Practices Analyzer (AD DS BPA) is not able to collect data about Group Policy Results setting “Access this computer from the network” from the domain controller .
Felet beror på att det ligger gamla konton i Default Domain Controllers policyn. Dessa konton anges med SID och då kan inte BPA översätta dom till kontonamn.
Åtgärd ta bort gamla konton från Default Domain Controllers policyn.
För att hitta dessa konton:
1. Starta Active Directory powershell i eleverat läge.
2. Skriv:
$doc=C:\Windows\System32\BestPractices\v1.0\Models\Microsoft\Windows\DirectoryServices\DirectoryServices_model.ps
3. Kontrollera vilka konton som inte kan översättas och ta bort dom.