new user script to send email with all the information

Good Morning below is a function that will gather all the information from a user and then send an email out to certain users with the information gather so far the email only comes with the correct columns but not the variables as shown below any help will be greatly appreciated.

Thank you 

 

function tony_user {

[CmdletBinding(SupportsShouldProcess = $True, ConfirmImpact = 'Low')]
param(
[Parameter(HelpMessage = 'Usersname', Position = 1)]
$Displayname)


# THIS IS ONLY FOR MY SCRIPT
$ScriptInfo = @{
SCRIPTNAME = 'tony New Hire'
AUTHOR = 'tony(jdacto)'
VERSION = '0.01'
CREATED = '2017-04-10'
LASTEDIT = '2017-04-10'
}

# THIS IS FOR THE LOG FUNCTION
$Global:WriteLog = @{
LogLevel = 'INFO'
LogToStdOut = $True
LogName = $ScriptInfo.SCRIPTNAME
LogDir = "c:\tony"
}

function Get-EmailBody {
param (
$ScriptStatus
)

$EmailBody = ''

$Displayname = $Displayname
$UserName = $UserName
$DefaultPassword = "Welcome1"
$EmailAddress = "$username@tonyco.com","$firstName.$lastName@tonyco.com"
$Phone = "456"
if ($Displayname) {
$EmailBody += "<h2>Displayname</h2>"
$EmailBody += ConvertTo-HTMLTable $Displayname
}

if ($UserName) {
$EmailBody += "<h2>UserName</h2>"
$EmailBody += ConvertTo-HTMLTable $userName
}
if ($DefaultPassword) {
$EmailBody += "<h2>DefaultPassword</h2>"
$EmailBody += ConvertTo-HTMLTable $DefaultPassword
}
if ($EmailAddress) {
$EmailBody += "<h2>EmailAddress</h2>"
$EmailBody += ConvertTo-HTMLTable $EmailAddress
}
if ($Phone) {
$EmailBody += "<h2>Phone</h2>"
$EmailBody += ConvertTo-HTMLTable $Phone
}
return $EmailBody
}
function Create-HostStatusObject {
param (
$Displayname,
$userName,
$defaultPassword,
$EmailAddress,
$phone
)
$_obj = New-Object -TypeName PSObject
$_obj | Add-Member -Type NoteProperty -Name Displayname -Value $Displayname
$_obj | Add-Member -Type NoteProperty -Name UserName -Value $userName
$_obj | Add-Member -Type NoteProperty -Name DefaultPassword -Value "Welcome1"
$_obj | Add-Member -Type NoteProperty -Name EmailAddress -Value "$username@tonyco.com","$firstName.$lastName@tonyco.com"
$_obj | Add-Member -Type NoteProperty -Name PhoneNumber -Value $phone

return $_obj
}

Function ConvertTo-HTMLTable {
param($inputTable)

$Header = @"
<style>
TABLE {border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
TH {border-width: 1px;padding: 3px;border-style: solid;border-color: black;background-color: #6495ED;}
TD {border-width: 1px;padding: 3px;border-style: solid;border-color: black;}
</style>
"@
return $inputTable | ConvertTo-Html -Head $Header
}


function New-UserServerFolders {
Param(
[Parameter(Position=0,Mandatory=$false,ValueFromPipelineByPropertyName=$false)]
[String]$server
,
[Parameter(Position=0,Mandatory=$false,ValueFromPipelineByPropertyName=$false)]
[String]$usershare
,
[Parameter(Position=1,Mandatory=$false,ValueFromPipelineByPropertyName=$false)]
[String]$user
)

$templateFolder = "\\$server\$usershare\Template"

Copy-Item -Recurse $templateFolder "\\$server\$usershare\$user"
$acl = Get-Acl $templateFolder

$inherit = [system.security.accesscontrol.InheritanceFlags]"ContainerInherit, ObjectInherit"
$propagation = [system.security.accesscontrol.PropagationFlags]"None"
$permission = "tony\$user","Modify",$inherit, $propagation, "Allow"

$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission
$acl.SetAccessRule($accessRule)
$acl | Set-Acl \\$server\$usershare\$user

icacls.exe "\\$server\$usershare\$user\*" /reset /T

}
function New-UserDFSFolders {
Param(
[Parameter(Position=0,Mandatory=$false,ValueFromPipelineByPropertyName=$false)]
[String]$server
,
[Parameter(Position=0,Mandatory=$false,ValueFromPipelineByPropertyName=$false)]
[String]$usershare
,
[Parameter(Position=0,Mandatory=$false,ValueFromPipelineByPropertyName=$false)]
[String]$profileshare
,
[Parameter(Position=1,Mandatory=$false,ValueFromPipelineByPropertyName=$false)]
[String]$user
)

dfscmd /map "\\tonyco.com\users\$user\Backups" "\\$server\$usershare\$user\backups"
dfscmd /map "\\tonyco.com\users\$user\Desktop" "\\$server\$usershare\$user\data\desktop"
dfscmd /map "\\tonyco.com\users\$user\Documents" "\\$server\$usershare\$user\data\documents"
dfscmd /map "\\tonyco.com\users\$user\Favorites" "\\$server\$usershare\$user\data\favorites"
dfscmd /map "\\tonyco.com\users\$user\Music" "\\$server\$usershare\$user\data\music"
dfscmd /map "\\tonyco.com\users\$user\Pictures" "\\$server\$usershare\$user\data\pictures"
dfscmd /map "\\tonyco.com\users\$user\Profile" "\\$server\$profileshare\$user\profile"
dfscmd /map "\\tonyco.com\users\$user\Profile.v2" "\\$server\$profileshare\$user\profile.v2"
dfscmd /map "\\tonyco.com\users\$user\Videos" "\\$server\$usershare\$user\data\videos"
}

$defaultPassword = ConvertTo-SecureString "Welcome1" -AsPlainText –Force

#$displayName = Read-Host "Display Name"

$names = $displayName.split(" ")

if($names.count -eq 2) {
$ScriptStatus = @()
$firstName = Read-Host "First Name [$($names[0])]"
$lastName = Read-Host "Last Name [$($names[1])]"

if($firstName -eq "") {$firstName = $($names[0])}
if($lastName -eq "") {$lastName = $($names[1])}

}
else {
$firstName = Read-Host "First Name"
$lastName = Read-Host "Last Name"
}

#Capitalize first letter of firstName and Lastname, rest is lowercase.
$firstName = $firstName.toLower()
$firstName = ([String]$firstName[0]).toUpper() + $firstName.substring(1)

$lastName = $lastName.toLower()
$lastName = ([String]$lastName[0]).toUpper() + $lastName.substring(1)


$defaultUsername = "$($firstName[0])$($lastName)".tolower()

$userName = Read-Host "Username [$defaultUsername]"
if($userName -eq "") {$userName = $defaultUsername}
$userName = $userName.tolower()

$office = Read-Host "Office Location (NY or LN)"
switch($office) {
"NY" {$office = 'New York - 7 WTC'; $userOU = 'tonyco.com/Global/Americas/Users'; $server = 'NTFS002'; $usershare = 'users$'; $profileshare = 'profiles$'}
"LN" {$office = 'London-Great Winchester'; $userOU = 'tonyco.com/Global/Europe/Users'; $server = 'LWFS004'; $usershare = 'usersv2$';$profileshare = 'profilesv2$' }
default {$office = 'New York - 7 WTC'; $userOU = 'tonyco.com/Global/Americas/Users'; $server = 'NTFS002'; $usershare = 'users$'; $profileshare = 'profiles$'}
}


""
""
""
"*****************************"
"Display Name: $displayName"
"First Name: $firstName"
"Last Name: $lastName"
"Username: $username"
"Phone Number: $phone"
"Server: $server"
"User Share: $usershare"
"Profile Share: $profileshare"
"User OU: $userOU"
"*****************************"
""
""
""
$ScriptStatus = Create-HostStatusObject -Name $DisplayName -Username $userName -Password "Welcome1" -PhoneNumber $phone -EmailAddress "$username@tonyco.com,$firstName.$lastName@tonyco.com"

#Write-Host $ScriptStatus
$EmailBody = Get-EmailBody $ScriptStatus
if ( $EmailBody) {
Send-Mail -emailSubject "New User $Displayname" -emailTo "$env:UserName@tonyco.com",'jdacto@tonyco.com' -emailBody $EmailBody
Write-Log -logString " [$FunName] Email sent"
}
}

  • Does it make a difference if you use the "-BodyAsHtml" switch when you call Send-Mail?
  • Import-Module \\dactoco.com\dfsshared\WinScons\scripts\PowerShell\PowerShellModules\dactoPowerShellModules.psm1 -Verbose
    import-module activedirectory

    ######################################Create New USER ##############################
    function dacto_user {

    [CmdletBinding(SupportsShouldProcess = $True, ConfirmImpact = 'Low')]
    param(
    [Parameter(HelpMessage = 'Usersname', Position = 1)]
    $Displayname)


    # THIS IS ONLY FOR MY SCRIPT
    $ScriptInfo = @{
    SCRIPTNAME = 'dacto New Hire'
    AUTHOR = 'tony(jdacto)'
    VERSION = '0.01'
    CREATED = '2017-04-10'
    LASTEDIT = '2017-04-10'
    }

    # THIS IS FOR THE LOG FUNCTION
    $Global:WriteLog = @{
    LogLevel = 'INFO'
    LogToStdOut = $True
    LogName = $ScriptInfo.SCRIPTNAME
    LogDir = "c:\dacto"
    }

    function Get-EmailBody {
    param (
    $ScriptStatus
    )

    $EmailBody = ''

    $Displayname = $ScriptStatus
    $UserName = $ScriptStatus
    $DefaultPassword = $ScriptStatus
    $EmailAddress = $ScriptStatus
    $Phone = $Phone
    $Location = $Office

    if ($Displayname) {
    $EmailBody += "<h2>New User</h2>"
    $EmailBody += ConvertTo-HTMLTable $Displayname
    }

    return $EmailBody
    }
    function Create-HostStatusObject {
    param (
    $Displayname,
    $userName,
    $defaultPassword,
    $EmailAddress,
    $phone,
    $Office
    )
    $_obj = New-Object -TypeName PSObject
    $_obj | Add-Member -Type NoteProperty -Name Displayname -Value $displayName
    $_obj | Add-Member -Type NoteProperty -Name UserName -Value $userName
    $_obj | Add-Member -Type NoteProperty -Name DefaultPassword -Value "testwww"
    $_obj | Add-Member -Type NoteProperty -Name EmailAddress -Value "$firstName.$lastName@dactoco.com"
    $_obj | Add-Member -Type NoteProperty -Name PhoneNumber -Value $Phone
    $_obj | Add-Member -Type NoteProperty -Name Office -Value $Office


    return $_obj
    }

    function New-UserServerFolders {
    Param(
    [Parameter(Position=0,Mandatory=$false,ValueFromPipelineByPropertyName=$false)]
    [String]$server
    ,
    [Parameter(Position=0,Mandatory=$false,ValueFromPipelineByPropertyName=$false)]
    [String]$usershare
    ,
    [Parameter(Position=1,Mandatory=$false,ValueFromPipelineByPropertyName=$false)]
    [String]$user
    )

    $templateFolder = "\\$server\$usershare\Template"

    Copy-Item -Recurse $templateFolder "\\$server\$usershare\$user"
    $acl = Get-Acl $templateFolder

    $inherit = [system.security.accesscontrol.InheritanceFlags]"ContainerInherit, ObjectInherit"
    $propagation = [system.security.accesscontrol.PropagationFlags]"None"
    $permission = "dacto\$user","Modify",$inherit, $propagation, "Allow"

    $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission
    $acl.SetAccessRule($accessRule)
    $acl | Set-Acl \\$server\$usershare\$user

    icacls.exe "\\$server\$usershare\$user\*" /reset /T

    }
    function New-UserDFSFolders {
    Param(
    [Parameter(Position=0,Mandatory=$false,ValueFromPipelineByPropertyName=$false)]
    [String]$server
    ,
    [Parameter(Position=0,Mandatory=$false,ValueFromPipelineByPropertyName=$false)]
    [String]$usershare
    ,
    [Parameter(Position=0,Mandatory=$false,ValueFromPipelineByPropertyName=$false)]
    [String]$profileshare
    ,
    [Parameter(Position=1,Mandatory=$false,ValueFromPipelineByPropertyName=$false)]
    [String]$user
    )

    dfscmd /map "\\dactoco.com\users\$user\Backups" "\\$server\$usershare\$user\backups"
    dfscmd /map "\\dactoco.com\users\$user\Desktop" "\\$server\$usershare\$user\data\desktop"
    dfscmd /map "\\dactoco.com\users\$user\Documents" "\\$server\$usershare\$user\data\documents"
    dfscmd /map "\\dactoco.com\users\$user\Favorites" "\\$server\$usershare\$user\data\favorites"
    dfscmd /map "\\dactoco.com\users\$user\Music" "\\$server\$usershare\$user\data\music"
    dfscmd /map "\\dactoco.com\users\$user\Pictures" "\\$server\$usershare\$user\data\pictures"
    dfscmd /map "\\dactoco.com\users\$user\Profile" "\\$server\$profileshare\$user\profile"
    dfscmd /map "\\dactoco.com\users\$user\Profile.v2" "\\$server\$profileshare\$user\profile.v2"
    dfscmd /map "\\dactoco.com\users\$user\Videos" "\\$server\$usershare\$user\data\videos"
    }





    $defaultPassword = ConvertTo-SecureString "testwww" -AsPlainText –Force

    $displayName = Read-Host "Display Name"

    $names = $displayName.split(" ")

    if($names.count -eq 2) {
    $firstName = Read-Host "First Name [$($names[0])]"
    $lastName = Read-Host "Last Name [$($names[1])]"

    if($firstName -eq "") {$firstName = $($names[0])}
    if($lastName -eq "") {$lastName = $($names[1])}

    }
    else {
    $firstName = Read-Host "First Name"
    $lastName = Read-Host "Last Name"
    }

    #Capitalize first letter of firstName and Lastname, rest is lowercase.
    $firstName = $firstName.toLower()
    $firstName = ([String]$firstName[0]).toUpper() + $firstName.substring(1)

    $lastName = $lastName.toLower()
    $lastName = ([String]$lastName[0]).toUpper() + $lastName.substring(1)


    $defaultUsername = "$($firstName[0])$($lastName)".tolower()

    $userName = Read-Host "Username [$defaultUsername]"
    if($userName -eq "") {$userName = $defaultUsername}
    $userName = $userName.tolower()

    $office = Read-Host "Office Location (NY or LN)"
    switch($office) {
    "NY" {$office = 'chine'; $userOU = 'dactoco.com/Global/Americas/Users'; $server = 'NTFS002'; $usershare = 'users$'; $profileshare = 'profiles$'}
    "LN" {$office = 'japan'; $userOU = 'dactoco.com/Global/Europe/Users'; $server = 'LWFS004'; $usershare = 'usersv2$';$profileshare = 'profilesv2$' }
    default {$office = 'chine'; $userOU = 'dactoco.com/Global/Americas/Users'; $server = 'NTFS002'; $usershare = 'users$'; $profileshare = 'profiles$'}
    }

    $phone = Read-Host "Phone number"

    ""
    ""
    ""
    "*****************************"
    "Display Name: $displayName"
    "First Name: $firstName"
    "Last Name: $lastName"
    "Username: $username"
    "Phone Number: $phone"
    "Server: $server"
    "User Share: $usershare"
    "Profile Share: $profileshare"
    "User OU: $userOU"
    "*****************************"
    ""
    ""
    ""
    $ScriptStatus += Create-HostStatusObject -DisplayName $displayname -Username $userName -office $Office -Phone $phone

    Write-Host $ScriptStatus
    $EmailBody = Get-EmailBody $ScriptStatus
    if ( $EmailBody) {
    Send-Mail -emailSubject "New Hire $Displayname" -emailTo 'heather.gibson@dactoco.com','Kendra.Costigan@dactoco.com','infra2@dactoco.com','Sophie.Barrett@dactoco.com' -emailBody $EmailBody
    Write-Log -logString " [$FunName] Email sent"
    }
    }