0

I am trying to perform something that is very similar to Excel. For example, the below script is what I have in PowerShell.

get-aduser -filter * -properties * | 
    sort-object name | 
    select Name, samaccountname, 
        @{Name="Manager";Expression={(get-aduser -property name $_.manager).name}}, 
        mail, office, officephone, homephone, ipPhone, telephonenumber, department, 
        city, streetaddress,company, CanonicalName, description | 
    where-object { $_.manager -ne $null -and $_.office -notlike "*123456*"}

My goal:

  1. Search the "notes" field in Active Directory for every employee.

  2. If it contains:

a. Hello = Put this in a new column called "NEW" and combine the fields with special characters. Example: (Phone Number@Desktop;).

b. GoodBye = Put this in a new column called "NEW" and combine the fields with special characters. Example: (Phone Number@Laptop;).

c. Orange = Put this in a new column called "NEW" and combine the fields with special characters. Example: (Phone Number@Tablet;).

  1. If it doesn't contain any of the specified criteria, show up as a blank in the "NEW" field.

Phone Number = $_.MobilePhone

Desktop/Laptop/Tablet = Strings

I have more criteria, but this is what I would like to accomplish. I'm a total beginner to Powershell and I believe that I need a calculated property, but I am not sure how to piece this together.

If this is in Excel, this is what I would do:

=IF(A1="GoodBye","1234567890@Laptop;",IF(A1="Orange","1234567890@Tablet;",IF(A1="Hello","1234567890@Desktop","")))
  • 2
    If I got it right you could use a calculated property just like you did for the property "Manager". – Olaf Feb 20 '21 at 21:13
  • 1
    See [this answer](https://stackoverflow.com/a/39861920/45375) for more information on calculated properties. – mklement0 Feb 20 '21 at 22:34

0 Answers0