I have two PS scripts, one reads from a list of computers on Sharepoint and outputs the results and the other outputs a list of computers from Active Directory.
What I need to do is somehow compare both of these lists to see: a) If list A has computers not listed on list B and b) If list B has computers not listed on list A
I'm assuming this may be possible using the Compare-Object cmdlet, and using arrays, but I'm not overly familiar with PS and not sure where to go from here.
To get the list of computers from AD I use:
Import-Module ActiveDirectory
$DCServer = "DC1.global"
$Searchbase = "OU=World,DC=global"
$list = Get-ADComputer -Server $DCServer -searchbase $Searchbase -Filter * -Property *
foreach($item in $list) {
write-host $item["Name"]
}
$Count = (Get-ADComputer -Server $DCServer -searchbase $Searchbase -Filter * -Property *).count
write-host "Total computers ="$count
To get the list of computers from Sharepoint I use:
Import-Module -DisableNameChecking "C:\Program Files (x86)\SharePointPnPPowerShellOnline\Modules\SharePointPnPPowerShellOnline"
$cred = Get_credential
connect-pnponline "https://domain.sharepoint.com/sites/Team" -credential $cred
$list = get-pnplistitem -list "HIVE_Devices"
foreach($item in $list)
{
write-host $item["Title"]
}