Powershell - Organizer Email Address - powershell

I'm trying to retrieve the email address of the Organizer of a meeting in MS Exchange 2010, using Powershell.
(Get-Mailbox -Identity "John Doe").PrimarySmtpAddress
I get the below error
The operation couldn't be performed because object 'John Doe' couldn't be found on 'xxxxxxxxxxxxxx'
These are for meetings that have just been created, so how can the Organizer not exist?
Edit:
Here's the sequence of events:
Fetch list of calendar events from exchange within specific date range
Fetch email address of Organizer for each event <-- this is where I'm stuck
Full script:
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username,$password
$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://xxxxxxxxxxxxxxx/PowerShell -Authentication kerberos -Credential $credential
Import-PSSession -Session $session -DisableNameChecking
#Date ranges
$exportDate = Get-Date -Format d
$startTime = (Get-Date).AddDays(-1)
$endTime = (Get-Date).AddDays(+1)
$app = New-Object -ComObject Outlook.Application
$ns = $app.GetNamespace('MAPI')
$calFolder = 9
$calItems = $ns.GetDefaultFolder($calFolder).Items
$calItems.Sort("[Start]")
$calItems.IncludeRecurrences = $true
$dateRange = "[Start] >= '{0}' AND [End] <= '{1}'" -f $startTime.ToString("g"), $endTime.ToString("g")
$calExport = $calItems.Restrict($dateRange)
$exportFile = "D:\file.csv"
$calExport | select Subject, StartInStartTimeZone, EndInEndTimeZone, Duration, Organizer, RequiredAttendees, OptionalAttendees, Location | sort StartUTC -Descending | Export-Csv $exportFile
$exportData = Import-Csv $exportFile
foreach ($line in $exportData)
{
$emailAddress = $line.Organizer
$emailAddress = (Get-Mailbox -Identity $line.Organizer).PrimarySmtpAddress
$line | Add-Member -Membertype Noteproperty -Name OrganizerEmail -Value $emailAddress
[array]$csvData += $line
$emailAddress = $null
}
Remove-PSSession $session
Please assist!

Here's what I used to get the Organizers email address
Get-ADUser -Filter {SamAccountName -like "*John Doe*"}

Related

how can i add credentials in New-PSSession? everytime i face the login-prompt (powershell)

im trying to schedule a powershellscript which changes the calender permissions of users within the group "kalender_rechten" to limited details. however im facing the login prompt on new-pssesion. how can i add the $credObject into New-PSSession, without the loginprompt?
#Start transcript
Start-Transcript -Path C:\temp\Set-DefCalPermissions.log -Append
#get credentials to authenticate
$username = "test.onmicrosoft.com"
$pwdTxt = Get-Content "C:\test\test\pw.txt"
$securePwd = $pwdTxt | ConvertTo-SecureString
$credObject = New-Object System.Management.Automation.PSCredential -ArgumentList
$username, $securePwd
#authenticate admin office365
get-credential $credObject
#create session Office365
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri
https://outlook.office365.com/powershell-liveid/ -Credential $credObject -Authentication
Basic –AllowRedirection
$credObject
#import Office365/exchange commands to PowerShell console
Import-PSSession $Session
# Get all user mailboxes
$Users = Get-DistributionGroupMember -Identity "Kalender_rechten"
# Permissions
$Permission = "LimitedDetails"
# Calendar name languages
$FolderCalendars = #("Agenda", "Calendar", "Calendrier", "Kalender")
# Loop through each user
foreach ($User in $Users) {
# Get calendar in every user mailbox
$Calendars = (Get-MailboxFolderStatistics $User.Identity -FolderScope Calendar)
# Loop through each user calendar
foreach ($Calendar in $Calendars) {
$CalendarName = $Kalender_rechten
# Check if calendar exist
if ($FolderCalendars -Contains $CalendarName) {
$Cal = $User.Identity.ToString() + ":\$CalendarName"
$CurrentMailFolderPermission = Get-MailboxFolderPermission -Identity $Cal - User Default
# Set calendar permission / Remove -WhatIf parameter after testing
Set-MailboxFolderPermission -Identity $Cal -User Default -AccessRights
$Permission -WarningAction:SilentlyContinue -WhatIf
# Write output
if ($CurrentMailFolderPermission.AccessRights -eq "$Permission") {
Write-Host $User.Identity already has the permission
$CurrentMailFolderPermission.AccessRights -ForegroundColor Yellow
}
else {
Write-Host $User.Identity added permissions $Permission -ForegroundColor Green
}
}
}
}
Stop-Transcript

Connect-MsolService - providing credentials without exposing password in script

I wish to run the below PowerShell script as a scheduled task to pull provisioning logs from Azure AD. However, I do not wish to embed the password. I appreciate this is not a problem specific to PowerShell or Microsoft Online. What technique can I use to not have the password stored as clear text? Thanks
Script credits go to: Pawel Janowicz
$AzureUsername = 'log.reader#tenant.net'
$Password = "xxxxxx"
$SecureString = ConvertTo-SecureString -AsPlainText $Password -Force
$SecuredCreds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $AzureUsername,$SecureString
$OutputCSV = "$Env:USERPROFILE\desktop\DirSyncProvisioningErrors_$(Get-Date -Format "yyyyMMdd").csv"
###### Connecting ############################################################################################################
Try{
[void] (Connect-MsolService -Credential $SecuredCreds)
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $SecuredCreds -Authentication Basic -AllowRedirection
[void] (Import-PSSession $Session -DisableNameChecking)
}
Catch{
$_.Exception.Message
Read-Host 'Press enter to close the window'
Remove-PSSession $Session
Exit
}
###### Getting errors ########################################################################################################
If(Get-MsolHasObjectsWithDirSyncProvisioningErrors){
Try{
$Errors = Get-MsolDirSyncProvisioningError -All | select DisplayName,ObjectID,ObjectType,ProvisioningErrors
$Results = Foreach ($i in $Errors){
$AllErrors = $i.ProvisioningErrors
$AllErrors | %{
$ErrorItem = $_
Get-AzureADObjectByObjectId -ObjectIds $i.objectid | Foreach{
New-Object PSObject -Property ([ordered]#{
'Displayname' = $i.displayname
'ObjectType' = $i.ObjectType
'Attribute' = $ErrorItem.propertyname
'Conflicting value' = $ErrorItem.propertyvalue
})
}
}
}
}
Catch{
$_.Exception.Message
Read-Host 'Press enter to close the window'
Remove-PSSession $Session
Exit
}
}
###### Results ###############################################################################################################
If($Results){
$Results | Format-Table -AutoSize
#Exporting CSV
$Results | Export-CSV $OutputCSV -NoTypeInformation -Force
}
Remove-PSSession $Session
Thank You Theo for providing your suggestion as a comment. Making this as answer to help other community member.
I have executed the command and getting a display to enter the password rather than it was manually provided in script itself.
$SecuredCreds = Get-Credential -UserName 'log.reader#tenant.net' -Message "Please enter credentials"
$OutputCSV = "$Env:USERPROFILE\desktop\DirSyncProvisioningErrors_$(Get-Date -Format "yyyyMMdd").csv"
###### Connecting ############################################################################################################
Try{
[void] (Connect-MsolService -Credential $SecuredCreds)
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $SecuredCreds -Authentication Basic -AllowRedirection
[void] (Import-PSSession $Session -DisableNameChecking)
}
Catch{
$_.Exception.Message
Read-Host 'Press enter to close the window'
Remove-PSSession $Session
Exit
}
###### Getting errors ########################################################################################################
If(Get-MsolHasObjectsWithDirSyncProvisioningErrors){
Try{
$Errors = Get-MsolDirSyncProvisioningError -All | select DisplayName,ObjectID,ObjectType,ProvisioningErrors
$Results = Foreach ($i in $Errors){
$AllErrors = $i.ProvisioningErrors
$AllErrors | %{
$ErrorItem = $_
Get-AzureADObjectByObjectId -ObjectIds $i.objectid | Foreach{
New-Object PSObject -Property ([ordered]#{
'Displayname' = $i.displayname
'ObjectType' = $i.ObjectType
'Attribute' = $ErrorItem.propertyname
'Conflicting value' = $ErrorItem.propertyvalue
})
}
}
}
}
Catch{
$_.Exception.Message
Read-Host 'Press enter to close the window'
Remove-PSSession $Session
Exit
}
}
###### Results ###############################################################################################################
If($Results){
$Results | Format-Table -AutoSize
#Exporting CSV
$Results | Export-CSV $OutputCSV -NoTypeInformation -Force
}
Remove-PSSession $Session

automate sitecollection administrator assignment in sharepoint online with powershell for backup purposes

I was asked to create a powershell script to automate the assignment for new sitecollection administrator in SharePoint-Online for BackUp purposes NetApp CloudControl.
This is my firsttime ever in PowerShell and now I got stucked and don't know where to look anymore or least don't understand what I'm looking at.
The script is supposed to do the following:
Get Microsoft-tenant and password
Create a new ps-script where the credentials are already filled in
Connect to sharepoint-online and lookup personal space for every user(onedrive for business sites)
cut the log and create a second one if more than 200 lines were written
read the log and make the service-account a sitecollectionadmin
create task to run the created script once per week
At the moment I got it to do this:
Get Microsoft-tenant and password
Save Credentials
Connect to sharepoint-online and lookup personal space for every user(onedrive for business sites)
read the log and make the service-account a sitecollectionadministrator
Can anyone of you please help me out on how to proceed with the next steps?
P.S. Please excuse that I'm posting the script as a whole, I just didn't know what I should cut out.
$TenantName = $null0
$TenantPassword = $null1
if($TenantName -eq $null0){
$TenantName = Read-Host "Enter Office 365 - Tenant Name."
$NewScript = Get-Content $PSCommandPath | ForEach-Object {$_ -replace '^\$TenantName = \$null0$',"`$TenantName = '$TenantName'"}
$NewScript | Out-File $PSCommandPath -Force
}
if($TenantPassword -eq $null1){
$TenantPassword = Read-Host "Enter Password for netapp-service#$($TenantName).onmicrosoft.com."
$NewScript = Get-Content $PSCommandPath | ForEach-Object {$_ -replace '^\$TenantPassword = \$null1$',"`$TenantPassword = '$TenantPassword'"}
$NewScript | Out-File $PSCommandPath -Force
}
$username = "netapp-service#$($TenantName).onmicrosoft.com"
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $userName, $(convertto-securestring $TenantPassword -asplaintext -force)
Connect-SPOService -Url https://$($TenantName)-admin.sharepoint.com/ -Credential $cred
$AdminURI = "https://$($TenantName)-admin.sharepoint.com"
$AdminAccount = "netapp-service#$($TenantName).onmicrosoft.com"
$AdminPass = $TenantPassword
$eDiscoveryUser = "netapp-service#$($TenantName).onmicrosoft.com"
$MySitePrefix = "https://$($TenantName)-my.sharepoint.com"
$LogFile = '.\$TenantName\$TenantName-MySites.txt'
$MySiteListFile = '.\$TenantName\$TenantName-MySites.txt'
Connect-SPOService -Url $AdminURI -Credential $cred
$loadInfo1 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
$loadInfo2 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
$loadInfo3 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.UserProfiles")
$sstr = ConvertTo-SecureString -string $AdminPass -AsPlainText –Force
$AdminPass = ""
$creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($AdminAccount, $sstr)
$proxyaddr = "$AdminURI/_vti_bin/UserProfileService.asmx?wsdl"
$UserProfileService= New-WebServiceProxy -Uri $proxyaddr -UseDefaultCredential False
$UserProfileService.Credentials = $creds
$strAuthCookie = $creds.GetAuthenticationCookie($AdminURI)
$uri = New-Object System.Uri($AdminURI)
$container = New-Object System.Net.CookieContainer
$container.SetCookies($uri, $strAuthCookie)
$UserProfileService.CookieContainer = $container
$UserProfileResult = $UserProfileService.GetUserProfileByIndex(-1)
Write-Host "Starting- This could take a while."
Out-File $LogFile -Force
$NumProfiles = $UserProfileService.GetUserProfileCount()
$i = 1
While ($UserProfileResult.NextValue -ne -1)
{
Write-Host "Examining profile $i of $NumProfiles"
$Prop = $UserProfileResult.UserProfile | Where-Object { $_.Name -eq "PersonalSpace" }
$Url= $Prop.Values[0].Value
if ($Url) {
$Url | Out-File $LogFile -Append -Force
}
$UserProfileResult = $UserProfileService.GetUserProfileByIndex($UserProfileResult.NextValue)
$i++
}
Write-Host "Done!"
$reader = [System.IO.File]::OpenText($MySiteListFile)
try {
for(;;) {
$line = $reader.ReadLine()
if ($line -eq $null) { break }
$fullsitepath = "$MySitePrefix$line"
Write-Host "Operating on $fullsitepath "
$fullsitepath = $fullsitepath.trimend("/")
Write-Host "Making $eDiscoveryUser a Site Collection Admin"
Set-SPOUser -Site $fullsitepath -LoginName $eDiscoveryUser -IsSiteCollectionAdmin $true
}
}
finally {
$reader.Close()
}
Disconnect-SPOService
Write-Host "Done!"

Powershell Speed Up Get-MessageTrackingLog

Currently I am trying to get an output of all disabled users and their message counts in exchange. This is easy enough through a foreach loop:
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://aserversomewhere.local/PowerShell/ -Authentication Kerberos -Credential $UserCredential
Import-PSSession $Session -AllowClobber
Import-Module ActiveDirectory
$Users = Get-ADUser -filter * -Properties * -SearchBase "OU=Disabled User Accounts,DC=Private,DC=Private"
$Today = (Get-Date).ToShortDateString()
$OneMonthAgo = (Get-Date).AddMonths(-1).ToShortDateString()
$results = #()
$OnPrem = $Users | Where-Object {$_.mDBUseDefaults -eq "True"}
$365 = $Users | Where-Object{$_.mDBUseDefaults -ne "True"}
Write-Host "Start Date: " $OneMonthAgo -ForegroundColor Green
Write-Host "Total Users OnPrem: " ($OnPrem.mail).Count -ForegroundColor Green
foreach($User in $OnPrem)
{
Write-Host "Checking User: "$User.DisplayName -ForegroundColor Yellow
$MessageCount = Get-MessageTrackingLog -recipients $User.Mail -Start $OneMonthAgo.ToString() | Where-Object {$_.EventID -eq "RECEIVE"} | Measure-Object
Write-Host $User.Name": MessageCount: "$MessageCount.Count -ForegroundColor Cyan
$Object = New-Object PSObject -Property #{
User = $User.Name
Email = $User.Mail
Type = "OnPrem"
DisabledDate = $User.Modified
Location = $User.Office
MessagesReceived = $MessageCount.Count
}
$script:results += $Object
}
The issue is this takes several hours to complete because it is being ran one user at a time. My Goal is to run multiple inquiries at a time either through jobs or in parallel. This needs to be ran in blocks of 10 due to the policy restrictions on the exchange server.
Edit (more information on why):
The reason to find the message counts of the users is, they are
disabled and sitting an a disabled OU. The reason for this is their
mail is fw to another recipient. Or, their mailbox has been delegated.
This is intended for house keeping. The results of this search will be
filtered by MessageCount = 0. Then it will either be reported/saved as
csv/users removed.
Disclosure: I am very ignorant on running jobs or running in parallel within powershell. And, my google-foo seems to be broken. Any guidance or help with this would be very appreciated.
Version info:
Name : Windows PowerShell ISE Host
Version : 5.1.15063.966
UPDATE:
After Following Shawn's guidance, I was able to successfully speed up these requests quite significantly.
Updated code:
$RunSpaceCollection = #()
$RunspacePool = [RunspaceFactory]::CreateRunspacePool(1, 10)
$RunspacePool.ApartmentState = "MTA"
$RunspacePool.Open()
$UserCredential = Get-Credential
Import-Module ActiveDirectory
$Users = Get-ADUser -filter * -Properties * -SearchBase "OU=Disabled User Accounts,DC=private,DC=private"
$Today = (Get-Date).ToShortDateString()
$OneMonthAgo = (Get-Date).AddMonths(-1).ToShortDateString()
[Collections.ArrayList]$results = #()
$OnPrem = $Users | Where-Object {$_.mDBUseDefaults -eq "True"}
$365 = $Users | Where-Object{$_.mDBUseDefaults -ne "True"}
Write-Host "Start Date: " $OneMonthAgo -ForegroundColor Green
Write-Host "Total Users OnPrem: " ($OnPrem.mail).Count -ForegroundColor Green
$scriptblock = {
Param (
[System.Management.Automation.PSCredential]$Credential,
[string]$emailAddress,
[string]$startTime,
[string]$userName,
[string]$loginName,
[string]$DisabledDate,
[string]$OfficeLocation
)
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://someserver.local/PowerShell/ -Authentication Kerberos -Credential $Credential
Import-PSSession $Session -AllowClobber -DisableNameChecking -Verbose:$false | Out-Null
$MessageCount = Get-MessageTrackingLog -recipients $emailAddress -Start $startTime.ToString() -ResultSize unlimited
$Object = New-Object PSObject -Property #{
User = $userName
Login = $loginName
Email = $emailaddress
Type = "OnPrem"
DisabledDate = $DisabledDate
Location = $OfficeLocation
MessagesReceived = $MessageCount.Count.ToString()
}
$Object
}
foreach($User in $OnPrem)
{
$Powershell = [PowerShell]::Create()
$null = $Powershell.AddScript($scriptblock)
$null = $Powershell.AddArgument($UserCredential)
$null = $Powershell.AddArgument($user.mail)
$null = $Powershell.AddArgument($OneMonthAgo)
$null = $Powershell.AddArgument($user.Name)
$null = $Powershell.AddArgument($user.samaccountname)
$null = $Powershell.AddArgument($user.Modified)
$null = $Powershell.AddArgument($user.Office)
$Powershell.RunspacePool = $RunspacePool
[Collections.ArrayList]$RunSpaceCollection += New-Object -TypeName PSObject -Property #{
RunSpace = $Powershell.BeginInvoke()
PowerShell = $Powershell
}
}
While($RunspaceCollection) {
Foreach($Runspace in $RunSpaceCollection.ToArray())
{
If ($Runspace.Runspace.IsCompleted) {
[void]$results.Add($Runspace.PowerShell.EndInvoke($Runspace.Runspace))
$Runspace.PowerShell.Dispose()
$RunspaceCollection.Remove($Runspace)
}
}
}
$RunspacePool.Close()
$RunspacePool.Dispose()
$results
The issue I am having is every user (except the last 3 users) are showing 0 as the message count. I know this wrong. Could this somehow not be waiting for the query of Get-MessageTrackingLog -sender to finish?
Example (77 Users total):
All but the last three show:
Email : a.b#something.com
DisabledDate : 02/08/2018
Login : a.b
Type : OnPrem
User : a, b
Location : Clearfield, IA
MessagesReceived : 0
In order to speedup Get-MessageTrackingLog, you have to use pools.
Original:
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://aserversomewhere.local/PowerShell/ -Authentication Kerberos -Credential $UserCredential
Import-PSSession $Session -AllowClobber
Import-Module ActiveDirectory
$Users = Get-ADUser -filter * -Properties * -SearchBase "OU=Disabled User Accounts,DC=Private,DC=Private"
$Today = (Get-Date).ToShortDateString()
$OneMonthAgo = (Get-Date).AddMonths(-1).ToShortDateString()
$results = #()
$OnPrem = $Users | Where-Object {$_.mDBUseDefaults -eq "True"}
$365 = $Users | Where-Object{$_.mDBUseDefaults -ne "True"}
Write-Host "Start Date: " $OneMonthAgo -ForegroundColor Green
Write-Host "Total Users OnPrem: " ($OnPrem.mail).Count -ForegroundColor Green
foreach($User in $OnPrem)
{
Write-Host "Checking User: "$User.DisplayName -ForegroundColor Yellow
$MessageCount = Get-MessageTrackingLog -recipients $User.Mail -Start $OneMonthAgo.ToString() | Where-Object {$_.EventID -eq "RECEIVE"} | Measure-Object
Write-Host $User.Name": MessageCount: "$MessageCount.Count -ForegroundColor Cyan
$Object = New-Object PSObject -Property #{
User = $User.Name
Email = $User.Mail
Type = "OnPrem"
DisabledDate = $User.Modified
Location = $User.Office
MessagesReceived = $MessageCount.Count
}
$script:results += $Object
}
With Jobs:
$MaxThread = 10
$RunspacePool = [runspacefactory]::CreateRunspacePool(
[System.Management.Automation.Runspaces.InitialSessionState]::CreateDefault()
)
[void]$RunspacePool.SetMaxRunspaces($MaxThread)
$RunspacePool.Open()
$UserCredential = Get-Credential
Import-Module ActiveDirectory
$Users = Get-ADUser -filter * -Properties * -SearchBase "OU=Disabled User Accounts,DC=private,DC=private"
$Today = (Get-Date).ToShortDateString()
$OneMonthAgo = (Get-Date).AddMonths(-1).ToShortDateString()
[Collections.ArrayList]$results = #()
$OnPrem = $Users | Where-Object {$_.mDBUseDefaults -eq "True"}
$365 = $Users | Where-Object{$_.mDBUseDefaults -ne "True"}
Write-Host "Start Date: " $OneMonthAgo -ForegroundColor Green
Write-Host "Total Users OnPrem: " ($OnPrem.mail).Count -ForegroundColor Green
$OnPremScriptblock = {
Param (
[System.Management.Automation.PSCredential]$Credential,
[string]$emailAddress,
[string]$startTime,
[string]$userName,
[string]$loginName,
[string]$DisabledDate,
[string]$OfficeLocation
)
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://aserversomewhere.local/PowerShell/ -Authentication Kerberos -Credential $Credential
Import-PSSession $Session -AllowClobber -DisableNameChecking -Verbose:$false | Out-Null
$MessageCount = Get-MessageTrackingLog -recipients $emailAddress -Start $startTime.ToString() -ResultSize unlimited
$Object = New-Object PSObject -Property #{
User = $userName
Login = $loginName
Email = $emailaddress
Type = "OnPrem"
DisabledDate = $DisabledDate
Location = $OfficeLocation
MessagesReceived = $MessageCount.Count.ToString()
}
$Object
}
$jobs = New-Object System.Collections.ArrayList
foreach ($user in $OnPrem){
$PowerShell = [PowerShell]::Create()
$null = $PowerShell.AddScript($OnPremScriptblock)
$null = $PowerShell.AddArgument($UserCredential)
$null = $PowerShell.AddArgument($user.mail)
$null = $PowerShell.AddArgument($OneMonthAgo)
$null = $PowerShell.AddArgument($user.name)
$null = $PowerShell.AddArgument($user.samaccountname)
$null = $PowerShell.AddArgument($user.modified)
$null = $PowerShell.AddArgument($user.Office)
$PowerShell.RunspacePool = $RunspacePool
[void]$jobs.Add((
[pscustomobject]#{
PowerShell = $PowerShell
Handle = $PowerShell.BeginInvoke()
}
))
}
While($jobs.handle.IsCompleted -eq $false){
Write-Host "." -NoNewline
Start-Sleep -Milliseconds 100
}
$return = $jobs | foreach{
$_.PowerShell.EndInvoke($_.Handle)
$_.PowerShell.Dispose()
}
$jobs.Clear()
$return
The results are stored in $return

PowerShell Script Balloon tip does not show $variable output

I have a script that is related to exchange online PowerShell. This script moves mail item from deleted mailbox to a new mailbox and once completed shows the balloon tip with the status. The Balloon tip script has a $variable which does not show the right output.
Script is as below:-
$User = "Admin#domain.com"
$mypass = cat "C:\pass.txt" | convertTo-securestring -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential ("$User", $mypass)
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $mycreds -Authentication Basic -AllowRedirection
Import-PSSession $Session
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.VisualBasic")
$DeletedUser = [Microsoft.VisualBasic.Interaction]::InputBox("Enter Deleted Mailbox Email Address", "Deleted Mailbox")
$UserMailbox = [Microsoft.VisualBasic.Interaction]::InputBox("Enter Destination Mailbox Email Address", "Destination Mailbox")
$DeletedGUID = Get-Mailbox -SoftDeletedMailbox $DeletedUser | fw guid
$DestinationGUID = Get-Mailbox $UserMailbox | fw guid
New-MailboxRestoreRequest -SourceMailbox $DeletedGUID -TargetMailbox $DestinationGUID -AllowLegacyDNMismatch
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$Status = Get-MailboxRestoreRequest | Get-MailboxRestoreRequestStatistics | FW StatusDetail
$objNotifyIcon = New-Object System.Windows.Forms.NotifyIcon
$objNotifyIcon.Icon = (join-path ([environment]::GetFolderPath('MyDocuments')) "EXO.ico")
$objNotifyIcon.BalloonTipIcon = "Error"
$objNotifyIcon.BalloonTipText = "Mail Item move has $Status"
$objNotifyIcon.BalloonTipTitle = "Operation $Status"
$objNotifyIcon.Visible = $True
$objNotifyIcon.ShowBalloonTip(50000)
The Balloon tip cannot parse the variable. Can anyone help?
Thanks in Advance!