Create Outlook appointment on specific account with command line - command-line

I have 2 accounts in my outlook configured, one is for example foo.bar#test.com. When I try to create an appointment via commandline OUTLOOK.EXE /c ipm.appointment, the appointment dialog appears, but its not assigend one of my accounts.
I recognize that when I add participant and try to send the appointment. Then the following message appears (translated):
This appointment is not in the folder "Calendar" for this account. Responses to this appointment will not be recorded. Do you want to contiune?
How can I create an appointment which is assigend to the folder "Calendar" to one of the existing accounts?

You could refer to this code:
$fieldservices = "0000000038A1BB1005E5..."
$outlook = new-object -comobject outlook.application
$namespace = $outlook.GetNameSpace("MAPI")
$calendar = $namespace.GetStoreFromID($fieldservices).GetDefaultFolder(9)
$appt = $Outlook.CreateItem(“olAppointmentItem”)
$root=$store.GetRootFolder()
$cal=$root.Folders.Item(5)
$appt.Move($cal)
#Making the appointment a meeting
$appt.MeetingStatus = 1
#Meeting one hour from current date and time
$appt.Start = $starttime
$appt.End = $appt.Start.AddMinutes($duration)
#Adding required attendees
$appt.RequiredAttendees = $tech
$appt.Subject = "$tech - $company: $summary - $ticket"
$appt.Location = "$address1 $address2 $city $zip"
$appt.Body = $body
$appt.Send()
For more information , Please reference this link:
Powershell Create Outlook Appointment

Related

Opening multiple MS Access application with powershell

Good day everyone. I'm new to powershell so I don't know what's wrong with this. I have this script to open multiple MS Access at once as you see in the script and it is save in my local drive. If I run this script in VS Code editor, the script is fine and two application is launch. Now if I run this script using mouse Right-Click and Run with powershell. At runtime, both application is visible but after the script completed/done, only one application is running and the other is closed.
$accessMenu = New-Object -ComObject Access.Application
$AccessPath1 = "G:\access1.MDB"
$accessMenu.OpenCurrentDatabase($AccessPath1, $false)
$accessMenu.Visible = $true
$accessLink = New-Object -ComObject Access.Application
$AccessPath2 = "G:\access2.accdb"
$accessLink.OpenCurrentDatabase($AccessPath2, $false)
$accessLink.Visible = $true
Am I missing something here? Thanks in advance for sharing your idea's.
Here is a VBScript that will open multiple dbs. It utilizes Windows Shell object. Create a text file and change the extension to vbs. Double click the file to run.
Dim objFSO1, objFS02, oShell1, oShell2
Set objFSO1 = CreateObject("Scripting.FileSystemObject")
Set oShell1 = CreateObject("WScript.Shell")
oShell1.Run """G:\access1.MDB"""
Set objFSO2 = CreateObject("Scripting.FileSystemObject")
Set oShell2 = CreateObject("WScript.Shell")
oShell2.Run """G:\access2.accdb"""
The only way I can get multiple databases to open and include a password is in VBA.
Option Compare Database
Option Explicit
Dim accdbObj1 As Access.Application
Dim accdbObj2 As Access.Application
____________________________________________________________________________
Sub test()
Set accdbObj1 = CreateObject("Access.Application")
accdbObj1.OpenCurrentDatabase "C:\Users\Owner\June\Forums\demofile.accdb", , "test"
accdbObj1.Application.Visible = True
Set accdbObj2 = CreateObject("Access.Application")
accdbObj2.OpenCurrentDatabase "C:\Users\Owner\June\DOT\Projects.accdb"
accdbObj2.Application.Visible = True
End Sub
For future preference:
As per #topsail said, by passing UserControl = $true in the instantiated variable of Access.Application it prevents the closing of object/application upon script termination/complete.
In powershell:
$accessObj = New-Object -ComObject Access.Application -Property #{UserControl = $true}
In VBA:
Dim accdbObj
Set accdbObj = CreateObject("Access.Application")
accdbObj.OpenCurrentDatabase "G:\path\test.mdb", , "password"
accdbObj.Application.Visible = True
accdbObj.UserControl = True

Forward emails with PowerShell and EWS Managed API

I have a PowerShell Script that uses EWS Managed API to fetch and processes specific emails from an inbox. If an email doesn't meet a condition its then forwarded to another inbox. the script works fine, but if it finds emails with attachments (that don't meet condition), it gets stuck to Draft folder and doesn't get sent. Any ideas?
The part of the code that forwards the emails.
Else {
$mail = New-Object Microsoft.Exchange.WebServices.Data.EmailMessage($service)
$OriginalEmail = $findResults.Items[0]
$psPropset= new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::IdOnly)
$psPropset.Add([Microsoft.Exchange.WebServices.Data.ItemSchema]::MimeContent)
$psPropset.Add([Microsoft.Exchange.WebServices.Data.ItemSchema]::Subject)
$OriginalEmail.Load($psPropset)
# Delete Received email after gathering the data
$findResults.delete([Microsoft.Exchange.WebServices.Data.DeleteMode]::MoveToDeletedItems,$True)
$AtColtype = ("Microsoft.Exchange.WebServices.Data.AttachmentCollection") -as "Type"
$Emailtype = ("Microsoft.Exchange.WebServices.Data.EmailMessage") -as "Type"
$methodInf = $AtColtype.GetMethod("AddItemAttachment");
$AddItmAttachMethod = $methodInf.MakeGenericMethod($Emailtype);
$EmailAttachment = $AddItmAttachMethod.Invoke($mail.Attachments,$null);
$EmailAttachment.Item.MimeContent = $OriginalEmail.MimeContent
$PR_Flags = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(3591, [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Integer);
$EmailAttachment.Item.SetExtendedProperty($PR_Flags,"1");
$EmailAttachment.Name = $OriginalEmail.Subject;
$mail.Subject = "$Subject";
$mail.ToRecipients.Add($ForwardToEmail);
$mail.SendAndSaveCopy();
$mail.Close()
}
Any help is appreciated.

How to add a certificate to a local Outlook contact using Powershell?

I am trying to sort out current contacts in Outlook to replace encryption certificates. But it is not clear how to prepare the object?
# В var $contactList collect contacts from Outlook
foreach ( $name in $contactList ) {
$PR_x509_Certificate = ('http://schemas.microsoft.com/mapi/proptag/0x3A701102');
# Create new contact
$NewContact = $Outlook.CreateItem('olContactItem');
# Get email, name, fullname from old contact
$NewContact.Email1Address = $name.Email1Address;
$NewContact.FullName = $name.FullName;
$NewContact.FirstName = $name.FirstName;
# Import certificate from из .cer file
$NewCertUser = New-Object system.security.cryptography.x509certificates.x509certificate2;
$NewCertUser.Import($PathToCerFile);
# Try add sertificate, but no success :(
$result = $NewCertUser.RawData;
$o = New-Object BuildProperty($result);
$NewContact.PropertyAccessor.SetProperty($PR_x509_Certificate, $o);
# Save new contact
$NewContact.Save();
# Delete old
$name.Delete();
}
I'm trying to update this:
It should be possible to do that on the users certificate store certmgr.msc without even touching Outlook:

How to add signature to powershell code creating new mail?

I want signatures to show up when creating new message as they do with Ctrl+N?
Here is my code:
$Outlook = New-Object -ComObject Outlook.Application
$Mail = $Outlook.CreateItem(0)
$Mail.To = "random.dude#email.com"
$Mail.Subject = "data for Subject"
$Mail.Body ="Example of body..."
$Mail.Signature = "Primary"
$inspector = $mail.GetInspector
$inspector.Display()
You could refer to the below code:
$Signature = "`n`nBest Regards,`nYourName`nyour#email.com"
$Mail.Body = "Si comunica che i pacchetti harvest $esito.`nSi rimanda alle verifiche del caso `nSaluti$Signature"
For more information, Please refer to this link:
Powershell email signature
The signature is added when Display is called as long as the message body is unmodified.
This means you must call Display first, and then merge your data with the body that the message has at this moment.
Also keep in mind that to keep the signature formatting, you must use the HTMLBody property rather than plain text Body. And you cannot simply concatenate two HTML strings - they must be merged.
If using Redemption (I am its author) is an option, it exposes RDOSignature.ApplyTo method, which allows to insert signature into an existing message.

Trying to use PowerShell to add a Parent Link to a TFS Task

I am trying to add a parent link when I create TFS task via powershell. However, I am only able to add a related link:
function Create-New-WorkItem($projName, $taskType, $title, $state, $assignedTo, $iterationPath, $activity, $BLItem)
{
$tfs = Get-TfsServer
$ws = $tfs.GetService([type]"Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore")
$proj = $ws.projects[$projName]
$workitem = $proj.workitemtypes[$taskType].newworkitem()
$workitem.open()
$workitem.title = $title
$workitem.state = $state
$workitem.fields["Assigned To"].value = $assignedTo
$workitem.iterationpath = $iterationPath
$workitem.fields["Activity"].value = $activity
$id = Get-Parent-Link $BLItem
$workitem.links.add($id.ID)
$workitem.close()
$workitem.save()
}
function Get-Parent-Link($backLogItemName)
{
$tfs = Get-TfsServer
$WIQL = #"
SELECT [System.Id]
FROM WorkItems
where [System.Title] = '$backLogItemName'
"#
return $tfs.wit.query($WIQL)
}
How can I add the link as a parent instead of a related?
After some trial and error I finally found a way to accomplish linking a new work item as a child to a parent item i.e. backlog item.
$ws = $tfs.GetService([type]"Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore")
$linkType = $ws.WorkItemLinkTypes[[Microsoft.TeamFoundation.WorkItemTracking.Client.CoreLinkTypeReferenceNames]::Hierarchy]
Add the workitem id of the parent you want to link the new child workitem to and create a workitemlink object:
$link = new-object Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemLink($linkType.ReverseEnd, 1234)
You can then add the link to a workitem:
$workitem.WorkItemLinks.Add($link)
$workitem.save()
You need to create a different link type object. A good exercise of the API can be found on Shai's blog.
http://blogs.microsoft.co.il/shair/2010/02/27/tfs-api-part-22-create-link-between-work-item-parent-child-etc/
The PowerShell for this is almost identical.