How to create contact list items in a SharePoint 2013 contact list with PowerShell? - powershell

I'm trying to create contact list items in a SharePoint 2013 contact list with powershell. Creating items itself is not that hard:
$spWeb = Get-SPWeb -Identity http://sharepoint
$spList = $spWeb.GetList("/Contacts/Lists/Test")
$spListItem = $spList.AddItem()
$spListItem["Title"] = "New Item"
$spListItem.Update()
But setting the properties like street, telephone number, position, etc. drives me crazy. When creating a contact manually in the list via the Website and getting the details of it with PowerShell ($spList.GetItems()), all those properties are put together in a property called Xml.
I know I can build the xml on my own and put it in there, but this just seems not to be the right way...
So my question is: How to create a contact item with properties like street, position, etc. correctly with PowerShell?
Update:
It looks like setting properties in the xml itself does not have any impact on the item. I tried:
[XML]$a = $spListItem["Xml"];
$a.row.SetAttribute("ows_FirstName", "New Firstname")
$spListItem.Update()
But this change does not appear on the Website nor when looking at the Xml again...

Ok, finally figured it out on my own...
$spListItem["Name"] = "Name"
$spListItem["FirstName"] = "FirstName"
$spListItem["FullName"] = "FullName"
$spListItem["Email"] = "Email"
$spListItem["Company"] = "Company"
$spListItem["JobTitle"] = "JobTitle"
$spListItem["WorkPhone"] = "WorkPhone"
$spListItem["HomePhone"] = "HomePhone"
$spListItem["CellPhone"] = "CellPhone"
$spListItem["WorkFax"] = "WorkFax"
$spListItem["WorkAddress"] = "WorkAddress"
$spListItem["WorkCity"] = "WorkCity"
$spListItem["WorkState"] = "WorkState"
$spListItem["WorkZip"] = "WorkZip"
$spListItem["WorkCountry"] = "WorkCountry"
$spListItem["WebPage"] = "http://WebPage.local"
$spListItem.Update()
It is really as simple as that...
There is also as MSDN article describing how to do it in C# at https://msdn.microsoft.com/en-us/library/office/ff521580(v=office.14).aspx

Related

How to replace/update the Value of an Attribute in LDAP Directory using PowerShell?

The entries in our companys Non-AD LDAP Server look like this:
uid = e145871
sn = Smith
givenName = John
department = Research & Development
department = Human Resource
And so on...
I've developed a PowerShell script to add specific attributes and values which is working just fine. Now I need to replace specific values but the issue is the identical attribute name. (In this case it's "department")
My goal is to replace "Research & Development" with "Something Else". If I run the following script it gets replaced but Human Resource is deleted as well. Is it possible to replace only one value without touching/deleting the other?
$r = New-Object -TypeName System.DirectoryServices.Protocols.ModifyRequest
$r.DistinguishedName = "uid=e145871,ou=identities,ou=users,o=items,dc=company,dc=domain,dc=com"
$DirectoryRequest_value = New-Object "System.DirectoryServices.Protocols.DirectoryAttributeModification"
$DirectoryRequest_value.Name = "department"
$DirectoryRequest_value.Contains("Research & Development")
$DirectoryRequest_value.Operation = [System.DirectoryServices.Protocols.DirectoryAttributeOperation]::Replace
$DirectoryRequest_value.Add("SomethingElse")
$r.Modifications.Add($DirectoryRequest_value)
$result = $connection.SendRequest($r)
Thanks!
The LDAP Replace operation replaces (or overwrites) the entire value of the attribute, including any existing values that might exist as part of a multi-valued attribute.
From RFC4511 ยง4.6 - "Modify Operation":
- operation: Used to specify the type of modification being
performed. Each operation type acts on the following
modification. The values of this field have the following
semantics, respectively:
[...]
replace: replace all existing values of the modification
attribute with the new values listed, creating the attribute
if it did not already exist. A replace with no value will
delete the entire attribute if it exists, and it is ignored
if the attribute does not exist.
Instead, add two separate modifications to the request - one to add "SomethingElse" and one to remove "Research & Development":
$targetObject = 'uid=e145871,ou=identities,ou=users,o=items,dc=company,dc=domain,dc=com'
$attributeName = 'department'
$oldValue = 'Research & Development'
$newValue = 'SomethingElse'
$request = [System.DirectoryServices.Protocols.ModifyRequest]::new()
$request.DistinguishedName = $targetObject
# This modification will add the new value "SomethingElse"
$addNewDepartment = #{
Name = $attributeName
Operation = 'Add'
} -as [System.DirectoryServices.Protocols.DirectoryAttributeModification]
$addNewDepartment.Add($newValue) |Out-Null
$request.Modifications.Add($addNewDepartment) |Out-Null
# This modification will remove the old value "Research & Development"
$removeOldDepartment = #{
Name = $attributeName
Operation = 'Delete'
} -as [System.DirectoryServices.Protocols.DirectoryAttributeModification]
$removeOldDepartment.Add($oldValue) |Out-Null
$request.Modifications.Add($removeOldDepartment) |Out-Null
$result = $connection.SendRequest($request)

BizTalk Orch/SMTP - Microsoft.XLANGs.BaseType.Content must be a message property of

This is related to my question from 2017: How Set Attachment Name to Show Properly in Outlook
This time, I have an orchestration with the following in a construct shape:
attachmentName = System.IO.Path.GetFileName(
msg_Ledger6002_File_XmlDoc
(FILE.ReceivedFileName));
msg_Email.BodyPart = new ABC.Ledger6002.Component.RawString("See attached email.");
msg_Email.AttachmentPart = msg_Ledger6002_File_XmlDoc;
// attachmentName is set earlier in orch so we could write it to EventLog for debugging
msg_Email.AttachmentPart(MIME.FileName) = attachmentName;
//msg_Email.AttachmentPart(MIME.ContentDescription) = "body";
//msg_Email.AttachmentPart(MIME.ContentTransferEncoding) = "base64";
// These are working
msg_Email(SMTP.Subject) = "Ledger6002 File";
msg_Email(SMTP.SMTPTo) = msg_Config_Email.smtpToEmail;
msg_Email(SMTP.From) = msg_Config_Email.smtpFromEmail;
msg_Email(SMTP.SMTPAuthenticate) = 0; // do not authenticate to SMTP server
// trying these two new parms below
msg_Email(SMTP.EmailBodyTextCharset) = "UTF-8";
msg_Email(Microsoft.XLANGs.BaseTypes.ContentType) = "text/plain";
The last line above gives me an expression shape not valid, and when I mouse over it it says identifies the error as:
Microsoft.XLANGs.BaseType.Content must be a message property of
msg_email.
Before I added the two lines under the comment "trying these two new parms below", I am getting an email with the desired attachment. The problem is that it is just called "body" and when I do "save as" from Outlook, it wants to call it "body" instead of the name of the file I dropped.
I'm using a "specify later" statically configured SendPort with PassThru for the Pipeline. I have tried a pipeline with MimeEncoder, but that caused the attachment to appear in the body. I would like to move to a dynamic pipeline, but so far I've got the static one working except for the name assigned to the file attachment.
To fix the error: "Microsoft.XLANGs.BaseType.Content must be a message property of msg_email.", I just needed to include the part name (the message is associated with a multipart message type, and I didn't include the partname):
Wrong:
msg_Email(Microsoft.XLANGs.BaseTypes.ContentType) = "text/plain";
Right:
msg_Email.BodyPart (Microsoft.XLANGs.BaseTypes.ContentType) = "text/plain";
I'm still working on getting the email with attachment to come out correctly, but so far this post https://social.msdn.microsoft.com/Forums/en-US/988b0d91-1e5a-4f73-b30d-417d6ea9fa75/attachment-name-in-outlook-is-ok-see-on-exchange-always-named-body?forum=biztalkgeneral seems to be the best explanation.

Outlook Distribution Lists (DistListItem) are not updated after a referenced contact (ContactItem) is changed

I've gathered some code from around the web to create Contacts and then Contact groups. However, if I update the contact after creation, the "relation" between the contact object inside the Contact group and the Contact is gone. The Contact group is not updated with the changes to the Contact.
If I manually create a Contact and Contact group, the relationship is just maintained as expected. Any ideas on what I could have missed?
Code for the Contact:
$olContactItem = 2
$o = new-object -comobject outlook.application
$c = $o.CreateItem($olContactItem)
$c.FullName = "Dummy Account"
$c.Email1Address = "aa#bb.com"
$a = $c.Save()
Code for the Contact group:
$outlook = new-object -com Outlook.Application
$contacts = $outlook.Session.GetDefaultFolder(10)
$session = $outlook.Session
$session.Logon("Outlook")
$namespace = $outlook.GetNamespace("MAPI")
$DL = $contacts.Items.Add("IPM.DistList")
$DL.DLName = "dummy2"
$recipient = $namespace.CreateRecipient("Dummy Account")
$recipient.Resolve()
$DL.AddMember($recipient)
$DL.Save()
Looks pretty straight forward to me. I checked the API, but that didn't get me much further.
https://msdn.microsoft.com/en-us/vba/outlook-vba/articles/recipients-object-outlook
Thanks in advance!
You add $recipient before it is initialized.
UPDATE: DistListItem.AddMember in OOM only adds one-off recipients, there is no way to add contacts. If using Redemption (I am its author) is an option, it exposes RDODistListItem.AddContact method that allows to pass either Outlook's ContactItem object or RDOContactItem object from Redemption. RDODistListItem also exposes AddMembers / AddMember / AddMemberEx methods.

Bugzilla email_in.pl reference several cc addresses

When a case is created from an e-mail, I would like the list of cc present in the e-mail to be added to my default bugzilla cc list.
I was able to do it with a single cc by doing :
my ($cc_address) = Email::Address->parse($input_email->header('Cc'));
$fields('cc') = $cc_address->address;
However, what if I have several addresses, I can capture them by doing :
my (#cc_address) = Email::Address->parse($input_email->header('Cc'));
then I am not sure about how to assign the list to $fields('cc').I don't think the field does expect a list.
Does anyone have an idea ?
Not tested, but have you tried:
my (#cc_address) = Email::Address->parse($input_email->header('Cc'));
my $cc_as_string = join ",", #cc_address;
$fields('cc') = $cc_as_string

How to get moodle module name from module id

I want to list the names of the modules (activities) in my course sections from moodle function or from db query.
I can get section details and module id from mdl_course_sections and mdl_course_modules tables I want to get name or tile put in every activity to be list down.
I already tried mod_frog_get_coursemodule_info($cm) but I hadn't any luck with it.
Use get_fast_mod_info() e.g.:
$modinfo = get_fast_modinfo($courseid);
foreach ($modinfo as $cm) {
echo $cm->modname;
}
I advise you :
$modinfo = get_fast_modinfo($courseid);
$cm = $modinfo->get_cm($moduleid);
Reference: https://docs.moodle.org/dev/Module_visibility_and_display#get_fast_modinfo_data
I found a solution to this with following code
$activity_modules = $DB->get_record('modules',array('id' =>$moduleid));
$dynamic_activity_modules_data = $DB->get_record($activity_modules->name,array('id' =>$instanceid));
echo $dynamic_activity_modules_data->name;
Use get_fast_modinfo() :
$cm = $modinfo->cms[$moduleid];
$modulename = $cm->modname;
This can be achieved in 2 lines within moodle structure:
global $DB;
$moduleName = $DB->get_field('modules','name',array('id' => $moduleID));