Thursday, November 16, 2023

Check AD user using Get-AdUser in Multi Domain Forest

Check AD user using Get-AdUser in Multi Domain Forest

Clear-Host
$UserEmail = 'user1@domain.com'
$Domains = (Get-ADForest).Domains
$DClist = ForEach ($Domain in $Domains) {
     Write-Host "Domain " $Domain
     Get-ADDomainController -DomainName $Domain -Discover -Service PrimaryDC | Select -ExpandProperty hostname
}
$ADUsersList = ForEach ($DC in $DClist) {
     Write-Host "DC: " $DC
     $adUser = Get-ADUser -server $DC -Filter { UserPrincipalName -eq $UserEmail }
     if (!$adUser) {
          Write-Host "`t User $UserEmail not exist" -b Red
     }
     else {
          Write-Host "`t User $UserEmail exist" -b Green
     }
     #Get-ADUser -server $DC -Filter * -Properties *
}
#$ADUsersList | Export-Csv -Path C:\ADUserList.csv -NoTypeInformation
 


Thursday, November 2, 2023

Copy a List in SharePoint Online Using PowerShell

Copy a List in SharePoint Online Using PowerShell

# 1. Copy with in site
$SiteURL = "https://SiteURL/sites/Retail/"
$SourceListName = "MyDocuments"
$DestinationListName = "MyDocuments_New"
 
Try {
  Connect-PnPOnline -Url $SiteURL -Interactive
  Copy-PnPList -Identity $SourceListName -Title $DestinationListName
}
Catch {
  write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
 
 
# 2. Copy to another site with in Site Collection
$SiteURL = "https://SourceSiteUrl/sites/Retail/"
$SourceListName = "MyDocuments"
 
$DestinationSiteURL = "https://DestinationSiteURL/sites/Sales/"
$DestinationListName = "MyDocuments_New"
 
Try {
  Connect-PnPOnline -Url $SiteURL -Interactive
  Copy-PnPList -Identity $SourceListName -Title $DestinationListName -DestinationWebUrl $DestinationSiteURL
}
Catch {
  write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
 
 
# 3. Copy to another Site Collection
$SourceSiteURL = "https://SourceSite/sites/one"
$TargetSiteURL = "https://TargetSite/sites/two"
$ListName = "TestList"
$TemplateFile = "C:\\Template.xml"
 
Connect-PnPOnline -Url $SourceSiteURL -Interactive
Get-PnPSiteTemplate -Out $TemplateFile -ListsToExtract $ListName -Handlers Lists
Add-PnPDataRowsToSiteTemplate -Path $TemplateFile -List $ListName
Connect-PnPOnline -Url $TargetSiteURL -Interactive
Invoke-PnPSiteTemplate -Path $TemplateFile

Featured Post

Mention a Channel or Team – Power Automate

Mention a Channel or Team – Power Automate graph.microsoft.com/v1.0/teams/{teamId}/channels/{channelId}/messages Channel: ---------- {   ...

Popular posts