Create File Folder and permission

I needed a quick script to include in my runbooks – one to create the home drive for my new user process. I got the base for this off the internet ( https://activedirectoryfaq.com/2017/09/powershell-create-home-directory-grant-permissions/ ) but I wanted to add a little bit of checking to see if the file existed first, etc.

param([Parameter(Mandatory=$true)][String]$samAccountName)

$User = Get-ADUser -Identity $samAccountName -Properties l

$office = $User.l

$homePath = "\\my.netork\user$\" + $Office + "\{0}" -f $samAccountName

 
if($User -ne $Null) {
	
	#check home path to make sure one doesn't already exist
	[string]$homepathtest = Test-Path $homePath
	
	If ($homepathtest -eq "False") 
		{
		#create home drive
	    $homeShare = New-Item -path $homePath -ItemType Directory -force -ea Stop
	 	
	    $acl = Get-Acl $homeShare
	 	
		#permissison home drive
	    $FileSystemRights = [System.Security.AccessControl.FileSystemRights]"Full"
	    $AccessControlType = [System.Security.AccessControl.AccessControlType]::Allow
	    $InheritanceFlags = [System.Security.AccessControl.InheritanceFlags]"ContainerInherit, ObjectInherit"
	    $PropagationFlags = [System.Security.AccessControl.PropagationFlags]"InheritOnly"
	 
	    $AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule ($User.SID, $FileSystemRights, $InheritanceFlags, $PropagationFlags, $AccessControlType)
	    $acl.AddAccessRule($AccessRule)
	 
	    Set-Acl -Path $homeShare -AclObject $acl -ea Stop
	 	
	    Write-Host ("HomeDirectory created at {0}" -f $homePath)
	
		}
		
	If($homepathtest -eq "true") {
		Write-Host ("Home Directory at {0} already exists" -f $homePath )
		}
	
#
} 

Cool tool for the Cireson Portal

The Cireson portal has it’s own web based pages for Knowledge articles – but what does one do when they have 4000 knowledge articles in Rich Text Format (RTF) stored in the SCSM knowledge base?

A guy named John Doyle was awesome and wrote a script and DLL to migrate the date! Go John! you are the hero of the day.


The other day, someone asked about migrating KB articles from the SCSM database to the Cireson Portal. 

I built a small PowerShell script to attempt this. The code is fairly simple. You need to place the MarkupConverter.dll file somewhere on the file system and then reference this path in the script. You also need to set the URL to your Portal Server, and your credentials to authenticate to the portal.

It uses SMLets to get the list of KB articles from the SCSM Server and then uploads the articles to the Cireson Portal using the API – AddOrUpdateHTMLKnowledgeApi.

The code converts the RTF content in the End User and Analyst content to XAML, and then converts this to HTML. I looks alright on my server, but I am not guaranteeing the accuracy of the conversion.

Please feel free to modify it and adapt it to your needs.


https://us.v-cdn.net/6026663/uploads/editor/8c/2q7dwesg4hb7.zip

So of course i wanted to know more about this “AddorUpdateHTMLKnowledgeAPI which lead me to here:


https://support.cireson.com/Help/Api/POST-api-V3-KnowledgeBase-AddOrUpdateHTMLKnowledgeApi

and of course the general Cireson help:

https://support.cireson.com/Help

SCSM Entity Explorer

Historically I have used the SMLets to query objects in SCSM and learn about classes and relationships. Powershell works – but it’s not always the most beautiful of interfaces.

I stumbled upon a blog article and SCSM Entity Explorer and I really can’t do it justice. There are a number of well written blog articles, so i am not going to bore you with reading mine – and I am going to replicate the info to find the articles here with the express understanding that please give credit where due.

The tool can be used to explore classes and relationships of objects in SCSM. This is invaluable for learning HOW Service Manager is structured… especially if like my company, you have done some customization on top of the standard management packs.

The tool can be located here:
https://gallery.technet.microsoft.com/SCSM-Entity-Explorer-68b86bd2

It was written by Dieter Gasser who’s blog can be found here:
https://blog.dietergasser.com/2014/05/08/scsm-entity-explorer/


And Xaptiy did an excellent job of explaining the tools use here: https://www.xapity.com/single-post/2017/05/27/How-to-use-SCSM-Entity-Explorer



Service Manager – Which user?

One of the challenges when working with MS Service Manager 2012/2016 is that while there are related user types for things like the affected user (for whom the ticket is related) or the portal user (who put the ticket in), etc – most of the questions in which you choose an Active directory user – are simply related as “related to” and thus – if you as for multiple, you are not 100% sure which is the answer to the question asked.

I find myself frequently looking for a user specified in the questions in my powershell script.

Now one way to determine the actual user is to parse the XML from the answers block and get the name and the question. Match it up and you are good to go.

Anthony Watherson over at microsoft did a good writeup on that process – so I will just link that here:

https://blogs.technet.microsoft.com/automagically/2014/11/16/dealing-with-xml-inputs-from-service-manager/

However – I use something else – Not because it’s necessarily “better” but simply because it popped into my head when i was working on it – and I didn’t google for the XML solution until a much later date… i.e. when I was looking to talk about this content.

For me – I use Cireson’s “multiple mapping” feature to map the name of the user chosen, to a property in the SR:

and eventually handed off to SCORCH and the runbook :

So that gives us the NAME of the user chosen.. but how do we make sure it’s the right user? We might have two John Smiths of Sameer Kumars after all.

We pass that information along the chain to a SCORCH workflow:




The script grabs the user from the name – and passes it to the get object which then returns it to be used by whatever workflow you might need to use that information in.

here is the Powershell:

#
Find Related User
#
Import-Module SMLETS
$SCSMServer = "scsmserver.app.intranet"
$SCSMServer = "localhost"
Set base variables
$SR = "PASSED IN VARIABLE"
$name = "PASSED IN VARIABLE"
$SR = "SR172196"
Establish GUIDS:
$RelationShipType = "System.WorkItemRelatesToConfigItem"
Establish relationship classes
$RouteToRelationship = Get-SCSMRelationshipClass -Name $($RelationShipType +"$") -ComputerName $SCSMServer
$SystemWorkItemAssignedToUserClass = Get-SCSMRelationshipClass -Name System.WorkItemAssignedToUser$ -ComputerName $SCSMServer
Get Service Request
$ServiceRequest = Get-SCSMObject -Class (Get-SCSMClass -Name System.WorkItem.ServiceRequest$ -ComputerName $SCSMServer) -ComputerName $SCSMServer -Filter "ID -eq $SR"
Get user Object
$RoutedToUser = (Get-SCSMRelationshipObject -BySource $ServiceRequest -ComputerName $SCSMServer | ?{$_.RelationshipID -eq $RouteToRelationship.Id -and $_.IsDeleted -eq $False})
#
Foreach ($relateduserobj in $RoutedToUser)
{
$smuserobj = $relateduserobj.TargetObject
If ($smuserobj.displayname -eq $Name)
{
$Global:Userobject = $smuserobj
}
}
$SAM = $Userobject.Name
$ArrSAM = $SAM.Split(".")
#
$outSAM = $ArrSAM[1]
$outname = $Userobject.DisplayName
$outGUID = $Userobject.IdNow this may not be useful to you... b

We use this because we already have it. I was easy to put together when I was looking for a solution. Maybe it’s also useful to someone else… if not… I thank you for at least reading my ramblings 🙂

A better portal..

One of the big limitations that Service manager has is gathering information on requests. In my company we utilize a third party browser based “head” for SCSM requests by a company called Cireson.

https://cireson.com/

Those guys all used to work for Microsoft and do good stuff. If you need any details – just reach out and ask.

A list of user info..

One of the things we commonly need is a list of user info. Putting that together in code is easy – but if we want a nice output to send to users? This does that.

$InputSAM = "SAMACCOUNTNAME"

############################
##
## Get user object
##
############################
$ObjUser = Get-ADUser -Identity $InputSAM -Properties *

############################
##
## Get user's manager Object
##
############################

$UserManager = $ObjUser.Manager
$ObjUserManager = Get-ADUser -Identity $UserManager -Properties OfficePhone,title

############################
##
## Zig the Zagged Data
##
############################

$DCS = Get-ADDomainController -Filter *
$NOW = Get-Date

#######################################
##
## HTML Stuff
##
######################################
$Goodgreen = "LimeGreen"
$name = $ObjUser.DisplayName

# TABLE

$tableHeader = "

"
$tableEnd = "
User Information for: " + $name + "

"
$line = "

"
$TableRow = "

"

# Cell

$CellStart = "

"
$defaultcolorCell = $TableBody + $CellStart + $Goodgreen + $cellMiddle1

### example
# $DistinguishedNameTitle = "Distinguished Name:"
# $DistinguishedNameColor = $Goodgreen
# $DistinguishedNamedata = $DistinguishedName
# $DistinguishedNameCells = $CellStart + $DistinguishedNameColor + $cellMiddle1 + $DistinguishedNameTitle + $Cellmiddle2 + $DistinguishedNamedata + $cellend

# $TableBody = $TableBody + $CellStart + $DistinguishedNameColor + $cellMiddle1 + $DistinguishedNameTitle + $Cellmiddle2 + $DistinguishedNamedata + $cellend

############################
##
## Data to return
##
############################

# start our Table body with a new line and a row

[string]$TableBody = $line + $TableRow

##################################################
# Who info

$name = $ObjUser.DisplayName
$nametitle = "Display Name: "
$namedata = $ObjUser.DisplayName
$TableBody = $TableBody + $defaultcolorCell + $NameTitle + $Cellmiddle2 + $Namedata + $cellend

$UserSAM = $objuser.SamAccountName
$UserSAMtitle = "Login: "
$UserSAMdata = $UserSAM
$TableBody = $TableBody + $defaultcolorCell + $UserSAMtitle + $Cellmiddle2 + $UserSAMdata + $cellend

#new Row
$TableBody = $TableBody + $TableRow

$title = $objuser.Title
$titletitle = "Title: "
$titledata = $title
$TableBody = $TableBody + $defaultcolorCell + $titletitle + $Cellmiddle2 + $titledata + $cellend

$Description = $ObjUser.Description
$Descriptiontitle = "Prefered Title: "
$Descriptiondata = $Description
$TableBody = $TableBody + $defaultcolorCell + $Descriptiontitle + $Cellmiddle2 + $Descriptiondata + $cellend

#new Row
$TableBody = $TableBody + $TableRow

$employeedepartment = $ObjUser.Department
$employeedepartmenttitle = "Department: "
$employeedepartmentdata = $employeedepartment
$TableBody = $TableBody + $defaultcolorCell + $employeedepartmenttitle + $Cellmiddle2 + $employeedepartmentdata + $cellend

$Company = $ObjUser.Company
$Companytitle = "Company: "
$Companydata = $Company
$TableBody = $TableBody + $defaultcolorCell + $Companytitle + $Cellmiddle2 + $Companydata + $cellend

#new Row
$TableBody = $TableBody + $TableRow

$DistinguishedName = $ObjUser.DistinguishedName
$DistinguishedNameTitle = "Distinguished Name: "
$DistinguishedNamedata = $ObjUser.DistinguishedName
$TableBody = $TableBody + $defaultcolorCell + $DistinguishedNameTitle + $Cellmiddle2 + $DistinguishedNamedata + $cellend

##################################################
# Employee Details

#new Line
$TableBody = $TableBody + $line

#Section header
$TableBody = $TableBody + "

"

#new Line
$TableBody = $TableBody + $line

#new Row
$TableBody = $TableBody + $TableRow

$officephone = $objuser.OfficePhone
$officephonetitle = "Office Phone: "
$officephonedata = $officephone
$TableBody = $TableBody + $defaultcolorCell + $officephonetitle + $Cellmiddle2 + $officephonedata + $cellend

$homephone = $ObjUser.HomePhone
$homephonetitle = "Home or Cell: "
$homephonedata = $homephone
$TableBody = $TableBody + $defaultcolorCell + $homephonetitle + $Cellmiddle2 + $homephonedata + $cellend

#new Row
$TableBody = $TableBody + $TableRow

$employeeID = $objuser.EmployeeID
$employeeIDtitle = "Employee ID: "
$employeeIDdata = $employeeID
$TableBody = $TableBody + $defaultcolorCell + $employeeIDtitle + $Cellmiddle2 + $employeeIDdata + $cellend

$employeetype = $ObjUser.employeeType
$employeetypetitle = "Account Type: "
$employeetypedata = $employeetype
$TableBody = $TableBody + $defaultcolorCell + $employeetypetitle + $Cellmiddle2 + $employeetypedata + $cellend

#new Row
$TableBody = $TableBody + $TableRow

$location = $ObjUser.Office
$locationtitle = "Office: "
$locationdata = $location
$TableBody = $TableBody + $defaultcolorCell + $locationtitle + $Cellmiddle2 + $locationdata + $cellend

$email = $ObjUser.EmailAddress
$emailtitle = "Email: "
$emaildata = $email
$TableBody = $TableBody + $defaultcolorCell + $emailtitle + $Cellmiddle2 + $emaildata + $cellend

###########################################
###
### We need to pause and Get the multi DC stuff
###
##############################################

$LastLogintime = 0
$DefenderLastLogintime = 0
$DCLastFailedLogintime = 0
$BadLogins = 0
$accountchangedtime = 0

foreach($dc in $dcs)
{
$hostname = $dc.HostName
$LocalDCuser = Get-ADUser $UserSAM -Server $hostname | Get-ADObject -Properties *

if($LocalDCuser.'defender-lastLogon' -gt $DefenderLastLogintime)
{
$DefenderLastLogintime = $LocalDCuser.'defender-lastLogon'
}
if($LocalDCuser.LastLogon -gt $LastLogintime)
{
$LastLogintime = $LocalDCuser.LastLogon
}
if($LocalDCuser.BadPasswordTime -gt $DCLastFailedLogintime)
{
$DCLastFailedLogintime = $LocalDCuser.BadPasswordTime
}

if($LocalDCuser.whenChanged -gt $accountchangedtime)
{
$accountchangedtime = $LocalDCuser.whenChanged
}

if($LocalDCuser.BadLogonCount -gt $BadLogins)
{
[string]$BadLogins = $LocalDCuser.BadLogonCount
}
}
$LastSuccessfulLogin = [DateTime]::FromFileTime($LastLogintime)
$DefenderLastSuccessfulLogin = [DateTime]::FromFileTime($DefenderLastLogintime)
$lastfailedlogin = [DateTime]::FromFileTime($DCLastFailedLogintime)
$Acctchanged = $accountchangedtime

# Echo $username
# Echo "last logged on at: " $LastSuccessfulLogin
# Echo "last logged on with Defender token at: " $DefenderLastSuccessfulLogin
# Echo "last FAILED log on at: " $lastfailedlogin
# Echo "Recent Bad Logins: " $BadLogins
#

###################################################
# Oddball Account Properties
#new Line
$TableBody = $TableBody + $line

#new Row
$TableBody = $TableBody + $TableRow

$AcctCreated = $ObjUser.whenCreated
$AcctCreatedtitle = "Account Creation Date: "
$AcctCreateddata = $ObjUser.whenCreated
$TableBody = $TableBody + $defaultcolorCell + $AcctCreatedtitle + $Cellmiddle2 + $AcctCreateddata + $cellend

$Acctchangedtitle = "Account Last Changed: "
$Acctchangeddata = $Acctchanged
$TableBody = $TableBody + $defaultcolorCell + $Acctchangedtitle + $Cellmiddle2 + $Acctchangeddata + $cellend

###################################################
# Login times and Status

#new Line
$TableBody = $TableBody + $line

#Section header
$TableBody = $TableBody + "

"

#new Line
$TableBody = $TableBody + $line

#new Row
$TableBody = $TableBody + $TableRow

$LastSuccessfulLogintitle = "Last Successful Login: "
$LastSuccessfulLogindata = $LastSuccessfulLogin
$TableBody = $TableBody + $defaultcolorCell + $LastSuccessfulLogintitle + $Cellmiddle2 + $LastSuccessfulLogindata + $cellend

$DefenderLastSuccessfulLogintitle = "Last Defender Token Login: "
$DefenderLastSuccessfulLogindata = $DefenderLastSuccessfulLogin
$TableBody = $TableBody + $defaultcolorCell + $DefenderLastSuccessfulLogintitle + $Cellmiddle2 + $DefenderLastSuccessfulLogindata + $cellend

#new Row
$TableBody = $TableBody + $TableRow

$lastfailedlogintitle = "Last Failed Login: "
$lastfailedlogindata = $lastfailedlogin
$TableBody = $TableBody + $defaultcolorCell + $lastfailedlogintitle + $Cellmiddle2 + $lastfailedlogindata + $cellend

################################################################
## account status

#new Line
$TableBody = $TableBody + $line

#Section header
$TableBody = $TableBody + "

"

#new Line
$TableBody = $TableBody + $line

#new Row
$TableBody = $TableBody + $TableRow

########## Account locked processing
$AcctLocked = $ObjUser.LockedOut
switch($AcctLocked)
{
True
{
$AccountLockedColor = "Red"
}
False
{
$AccountLockedColor = "LimeGreen"
}
}

$AcctLockedtitle = "Account Locked: "
$AcctLockeddata = $AcctLocked
$TableBody = $TableBody + $CellStart + $AccountLockedColor + $cellMiddle1 + $AcctLockedtitle + $Cellmiddle2 + $AcctLockeddata + $cellend

######### account control processing

$AccountControl = $ObjUser.userAccountControl
switch($AccountControl)
{
512
{
$accountDisabled = "False"
$accountDisabledColor = "LimeGreen"
$passwordexpires = "True"
$passwordexpirescolor = "LimeGreen"
}
514
{
$accountDisabled = "True"
$accountDisabledColor = "Red"
$passwordexpires = "True"
$passwordexpirescolor = "LimeGreen"
}
66048
{
$accountDisabled = "False"
$accountDisabledColor = "LimeGreen"
$passwordexpires = "false"
$passwordexpirescolor = "DarkOrange"
}
66050
{
$accountDisabled = "True"
$accountDisabledColor = "Red"
$passwordexpires = "false"
$passwordexpirescolor = "DarkOrange"
}
}

$accountDisabledtitle = "Account Disabled: "
$accountDisableddata = $accountDisabled
$TableBody = $TableBody + $CellStart + $accountDisabledColor + $cellMiddle1 + $accountDisabledtitle + $Cellmiddle2 + $accountDisableddata + $cellend

################################################################
## password status

#new Line
$TableBody = $TableBody + $line

#Section header
$TableBody = $TableBody + "

"

#new Line
$TableBody = $TableBody + $line

#new Row
$TableBody = $TableBody + $TableRow

$pwdlastChanged = $ObjUser.PasswordLastSet
$pwdlastChangedtitle = "Password Last Set: "
$pwdlastChangeddata = $pwdlastChanged
$TableBody = $TableBody + $defaultcolorCell + $pwdlastChangedtitle + $Cellmiddle2 + $pwdlastChangeddata + $cellend

########## password age calculation
$PwdAge = ($NOW - $pwdlastChanged).days

switch($PwdAge)
{
{$_ -ge 0 -and $_ -le 45}
{
$PwdAgeColor = "LimeGreen"
}
{$_ -ge 46 -and $_ -le 55}
{
$PwdAgeColor = "Yellow"
}
{$_ -ge 56 -and $_ -le 60}
{
$PwdAgeColor = "DarkOrange"
}
{$_ -ge 61}
{
$PwdAgeColor = "Red"
}
}

$PwdAgetitle = "Password Age: "
$PwdAgedata = $PwdAge
$TableBody = $TableBody + $CellStart + $PwdAgeColor + $cellMiddle1 + $PwdAgetitle + $Cellmiddle2 + $PwdAgedata + $cellend

#new Row
$TableBody = $TableBody + $TableRow

$passwordexpirestitle = "Password Expires Policy: "
$passwordexpiresdata = $passwordexpires
$TableBody = $TableBody + $CellStart + $passwordexpiresColor + $cellMiddle1 + $passwordexpirestitle + $Cellmiddle2 + $passwordexpiresdata + $cellend

$PwdExpired = $ObjUser.PasswordExpired
switch($PwdExpired)
{
False
{
$pwdExpiredColor = "LimeGreen"
}
True
{
$pwdExpiredColor = "Red"
}
}

$PwdExpiredtitle = "Password Expired?: "
$PwdExpireddata = $PwdExpired
$TableBody = $TableBody + $CellStart + $PwdExpiredColor + $cellMiddle1 + $PwdExpiredtitle + $Cellmiddle2 + $PwdExpireddata + $cellend

#new Row
$TableBody = $TableBody + $TableRow

$UserchangePwd = $ObjUser.CannotChangePassword

switch($UserchangePwd)
{
False
{
$UserChangepwdColor = "LimeGreen"
$UserchangePwdStatus = "Yes"
}
True
{
$UserChangepwdColor = "Yellow"
$UserchangePwdStatus = "No"
}
}

$UserchangePwdtitle = "User can change password?: "
$UserchangePwddata = $UserchangePwdStatus
$TableBody = $TableBody + $CellStart + $UserchangePwdColor + $cellMiddle1 + $UserchangePwdtitle + $Cellmiddle2 + $UserchangePwddata + $cellend

# Domain Password Policy stuff
$ADDomainPasswordPolicy = Get-ADDefaultDomainPasswordPolicy

#new Row
$TableBody = $TableBody + $TableRow

[string]$maxattempts = $ADDomainPasswordPolicy.LockoutThreshold
[string]$Remainingattempts = $maxattempts - $BadLogins

$maxattemptstitle = "Max/Remaining Password Attempts: "
[string]$maxattemptsdata = $maxattempts + " / " + $Remainingattempts
$TableBody = $TableBody + $defaultcolorCell + $maxattemptstitle + $Cellmiddle2 + $maxattemptsdata + $cellend

########## calculate account unlock policy
$LockoutDuration = $ADDomainPasswordPolicy.LockoutDuration
if ($LockoutDuration -le 0)
{
$Autounlock = "Manual Unlock Only"
}
if ($LockoutDuration -gt 0)
{
$Autounlock = "[Days:Hours:Minutes] " + $LockoutDuration
}

$Autounlocktitle = "Auto Unlock Duration: "
$Autounlockdata = $Autounlock
$TableBody = $TableBody + $defaultcolorCell + $Autounlocktitle + $Cellmiddle2 + $Autounlockdata + $cellend

#new Row
$TableBody = $TableBody + $TableRow

$MinPwdlength = $ADDomainPasswordPolicy.MinPasswordLength
$MinPwdlengthtitle = "Minimum Password Length: "
$MinPwdlengthdata = $MinPwdlength
$TableBody = $TableBody + $defaultcolorCell + $MinPwdlengthtitle + $Cellmiddle2 + $MinPwdlengthdata + $cellend

$MinPwdHistory = $ADDomainPasswordPolicy.PasswordHistoryCount
$MinPwdHistorytitle = "Minimum Password History: "
$MinPwdHistorydata = $MinPwdHistory
$TableBody = $TableBody + $defaultcolorCell + $MinPwdHistorytitle + $Cellmiddle2 + $MinPwdHistorydata + $cellend

################################################################
## Profile Information

#new Line
$TableBody = $TableBody + $line

#Section header
$TableBody = $TableBody + "

"

#new Line
$TableBody = $TableBody + $line

#new Row
$TableBody = $TableBody + $TableRow

$Script = $ObjUser.ScriptPath
$Scripttitle = "Login Script: "
$Scriptdata = $Script
$TableBody = $TableBody + $defaultcolorCell + $Scripttitle + $Cellmiddle2 + $Scriptdata + $cellend

#new Row
$TableBody = $TableBody + $TableRow

$homeLocation = $ObjUser.l
$HomeDirectory = "\\microsoft.com\user\" + $homeLocation + "\" + $UserSAM + "\"
$HomeDirectorytitle = "Home Drive: "
$HomeDirectorydata = $HomeDirectory
$TableBody = $TableBody + $defaultcolorCell + $HomeDirectorytitle + $Cellmiddle2 + $HomeDirectorydata + $cellend

#new Row
$TableBody = $TableBody + $TableRow

$CitrixProfile = "\\micosoft.com\citrix\Profiles\TS\" + $UserSAM +"
" + "\\microsoft.com\citrix\Profiles\TS-x64\" + $UserSAM
$CitrixProfiletitle = "Citrix Profiles: "
$CitrixProfiledata = $CitrixProfile
$TableBody = $TableBody + $defaultcolorCell + $CitrixProfiletitle + $Cellmiddle2 + $CitrixProfiledata + $cellend

################################################################
## Exchange information

#new Line
$TableBody = $TableBody + $line

#Section header
$TableBody = $TableBody + "

"

#new Line
$TableBody = $TableBody + $line

#new Row
$TableBody = $TableBody + $TableRow

$ExchangeAccount = $ObjUser.msExchWhenMailboxCreated
$ExchangeAccounttitle = "Mailbox Created: "
$ExchangeAccountdata = $ExchangeAccount
$TableBody = $TableBody + $defaultcolorCell + $ExchangeAccounttitle + $Cellmiddle2 + $ExchangeAccountdata + $cellend

#new Row
$TableBody = $TableBody + $TableRow

$proxyaddresses = $ObjUser.proxyAddresses

Foreach ($mailitem in $proxyaddresses)
{
$mailitemlist = $mailitemlist + "
" + $mailitem
}

$proxyaddressestitle = "Messaging Addresses: "
$proxyaddressesdata = $mailitemlist
$TableBody = $TableBody + $defaultcolorCell + $proxyaddressestitle + $Cellmiddle2 + $proxyaddressesdata + $cellend

#new Row
$TableBody = $TableBody + $TableRow

$AssignedDelegates = $ObjUser.publicDelegatesBL

Foreach ($mailbox in $AssignedDelegates)
{
$objmailbox = Get-ADUser -Identity $mailbox
$mailboxname = $objmailbox.name
$Publicmailbox = $publicmailbox + "
" + $mailboxname
}

$AssignedDelegatestitle = "Assigned Delegates: "
$AssignedDelegatesdata = $Publicmailbox
$TableBody = $TableBody + $defaultcolorCell + $AssignedDelegatestitle + $Cellmiddle2 + $AssignedDelegatesdata + $cellend

$mailboxmanager = $ObjUser.msExchDelegateListBL

Foreach ($mailbox in $mailboxmanager)
{
$objmailbox = Get-ADUser -Identity $mailbox
$mailboxname = $objmailbox.name
$mailboxlist = $mailboxlist + "
" + $mailboxname
}

$mailboxmanagertitle = "Delegate Access: "
$mailboxmanagerdata = $mailboxlist
$TableBody = $TableBody + $defaultcolorCell + $mailboxmanagertitle + $Cellmiddle2 + $mailboxmanagerdata + $cellend

############################
##
## Managers Data to return
##
############################

################################################################
## Manager information

#new Line
$TableBody = $TableBody + $line

#Section header
$TableBody = $TableBody + "

"

#new Line
$TableBody = $TableBody + $line

#new Row
$TableBody = $TableBody + $TableRow

$manager = $ObjUserManager.Name
$managertitle = "Manager Name: "
$managerdata = $manager
$TableBody = $TableBody + $defaultcolorCell + $managertitle + $Cellmiddle2 + $managerdata + $cellend

#new Row
$TableBody = $TableBody + $TableRow

$managertitle = $ObjUserManager.title
$managertitletitle = "Manager Title: "
$managertitledata = $managertitle
$TableBody = $TableBody + $defaultcolorCell + $managertitletitle + $Cellmiddle2 + $managertitledata + $cellend

$managerphone = $ObjUserManager.OfficePhone
$managerphonetitle = "Manager Office Phone: "
$managerphonedata = $managerphone
$TableBody = $TableBody + $defaultcolorCell + $managerphonetitle + $Cellmiddle2 + $managerphonedata + $cellend

###################################
##
## Message
##
#############################################################################

$Message = $Message + $tableHeader + $Tablebody + $tableend

This gives us pretty output we can send to users. I hope it helps.


"
$Cellmiddle2 = "
"
$cellend = "
EMPLOYEE DETAILS
LOGIN DATES
ACCOUNT STATUS
PASSWORD INFORMATION
PROFILE INFORMATION
EXCHANGE INFORMATION
LINE MANAGER