Notification

Icon
Error

Print Last OU instead of Full OU

Posted: Monday, January 11, 2021 9:26:50 PM(UTC)
Michael White

Michael White

Member Original PosterPosts: 4
0
Like
When I add tblADComputers.OU into a report, it prints the entire OU. Is there a way to have it only print the lowest level OU?

Ex:

Instead of printing `OU=WebServers,OU=Servers,OU=Computers,DC=EXAMPLE,DC=COM`

Just print `OU=WebServers`

Or even just `WebServers`
RC62N
#1RC62N Member Posts: 511  
posted: 1/11/2021 10:08:39 PM(UTC)
Take a look at the T-SQL string functions. You can use CharIndex() to check for the presence of a comma and, if present, return a truncated string using Left(), something like
Code:
CASE
  WHEN CharIndex(',', fullOU) > 0
  THEN Left(fullOU, CharIndex(',', fullOU)-1)
  ELSE fullOU
END AS lowOU

The simplest way to drop the "OU=" would probably be to wrap the CASE in a Replace().

Active Discussions

Lansweeper LSAgent Rescan Asset
by  marck1024   Go to last post Go to first unread
Last post: Yesterday at 4:11:53 PM(UTC)
Lansweeper Allowing a role to create asset groups
by  mh6543   Go to last post Go to first unread
Last post: 2/26/2021 10:00:40 PM(UTC)
Lansweeper Export LsAgent Assets
by  steveb  
Go to last post Go to first unread
Last post: 2/26/2021 7:26:32 PM(UTC)
Lansweeper Asset Uptime "Asset on total"
by  Andy.S   Go to last post Go to first unread
Last post: 2/26/2021 3:07:35 PM(UTC)
Lansweeper Scanning for Static Routes?
by  ChrisParr  
Go to last post Go to first unread
Last post: 2/26/2021 12:43:28 PM(UTC)
Lansweeper lansweeperuser sql database permissions
by  David K.   Go to last post Go to first unread
Last post: 2/25/2021 11:54:38 PM(UTC)
Lansweeper Scanning certificates
by  Vincent Pollock  
Go to last post Go to first unread
Last post: 2/25/2021 8:35:11 PM(UTC)