Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

checking of object is empty

$
0
0

I am trying to do something simple and have used the same methode in the past, but it does not seem to work.

I am doing a query in AD according to an csv file, and I want to perform certain tasks depending on the amount of objects returned. I thought I would create and object and check the value of the object returned to perform the desired task. However it is not working:

    $getuser = Get-ADUser -Filter "EmailAddress -eq '$mailAddr'" -Properties EmailAddress -Server $dom
	If ($getuser -eq $null) {
		Write-Host "No user with $($Mailaddr) was found in the $($dom) domain."
		$NotFound += $MailAddr
		}
	If ($getuser -gt "1") {
		Write-Host "Multiple objects have been found that are represented by $($MailAddr)."
		$MultipleEntries += $MailAddr 
		}
	Else {
		Set-ADUser $getuser.samaccountname -EmployeeID $EmpID -WhatIf
		$mods += $getuser | select EmploeeID, Firstname, Surname, DisplayName, Mail 
		}

I also tried:

if (!$variable) {$then}
if ($variable) {$then}

Or

If ($Variable -eq $null) {$do | Tee-Object $Notfound -append}
If ($Variable -gt "1") {$do | Tee-Object $MultipleObjects -append}
etc.

The result i get is that Powershell cant compare

Cannot compare "CN=Smith John,OU=Users,OU=Country,.

or

Bad argument to operator '-gt': Cannot compare "CN=Smith John,OU=Users


Answers provided are coming from personal experience, and come with no warranty of success. I as everybody else do make mistakes.


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>