bulk etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
bulk etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

29 Kasım 2016 Salı

Office 365 Account Creation and Bulk Email User Details with Powershell

If you have purchased office365 to be used in your organization, your first duty is to open accounts in office 365 after configuring related DNS settings in your DNS server.

To open these accounts in bulk you can use  office365 admin panel import pane. But without going to admin panel you can manage this tedious work using powershell.

The following powershell script will help you to

  • Create  Accounts
  • Assign Office365 License Pack you have
  • Export Created Account  details including assigned temproary passwords in NewAccountResults.csv file.  


Beforehand you should have  list of your staffs details in users.csv file.



#Pop-up will appear and wait you to enter administrator account credentials
$credential = get-credential

#Imports the installed Azure Active Directory module.
Import-Module MSOnline

#Establishes Online Services connection to Office 365 Management Layer.
Connect-MsolService -Credential $credential

#Create Users
Import-Csv .\users.csv | ForEach-Object {
#Generate Random Password
$office_365_password = ([char[]]([char]33..[char]95) + ([char[]]([char]97..[char]126)) + 0..9 | sort {Get-Random})[0..8] -join ''
#Create User
New-MsolUser -UserPrincipalName $_.UserPrincipalName -DisplayName $_.DisplayName -Password $office_365_password -UsageLocation $_.UsageLocation
}|Export-Csv -Path ".\NewAccountResults.csv"

#Assing License Pack to the unlicensed users
Get-MsolUser -All -UnlicensedUsersOnly  | Set-MsolUserLicense  -AddLicenses "yourdomain365:OFFICESUBSCRIPTION_PACKNAME"

Then you should send the temproary passwords created  to the personal email acounts of your staff by using the following powershell script.


#From : Sender Email Account 
$EmailFrom = "Name Surname <sender@domain.com>"
 
# Reporting: Report on Success and Failure (optional)
$EmailDeliveryNotificationOption = "onSuccess, onFailure"
 
# Server: Your Email SMTP server
$EmailSMTPserver = "mail.example.com"


# Users: csv file path, file includes  Name, PersonelEmail, Office365Account, Password
$SourcePath = ".\mail_merge_powerdshell.csv"
 
# Import csv file
$Users = Import-Csv  -Path $SourcePath
 
# ####################
# END Variables
# ####################
 
# Begin Loop: Do the following with each row of the file you imported, referencing columns by their header
foreach ($User in $Users) {
 
# To: User's email address
$EmailTo = $User.PersonelEmail
 
# Subject: Email subject (may merge variables)
$EmailSubject = "About Your Office365 Account " + $User.Name + "."
 
# Body: Email body, with HTML formatting
$EmailBody = "<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">"
$EmailBody += "<html xmlns=""http://www.w3.org/1999/xhtml""><head>"
$EmailBody += "<meta http-equiv=""Content-Type"" content=""text/html; charset=UTF-8"" />"
$EmailBody += "<meta name=""viewport"" content=""width=device-width, initial-scale=1.0""/>"
$EmailBody += "<title>" + $EmailSubject + "</title>"
$EmailBody += "</head><body bgcolor=""#FFFFFF"" style=""font-family: sans-serif; color: #000000"">"
$EmailBody += "<p>Dear " + $User.Name + ":</p>"
$EmailBody += "<p>Our Organization has purchased Office365 subscription for 1 Year</p>"
$EmailBody += "<li>Your Office365 Account: <strong>" + $User.Office365Account + "</strong></li></ul></p>"
$EmailBody += "<li>Your Office365 Account Password: <strong>" + $User.Password + "</strong></li></ul></p>"
$EmailBody += "<li>You can Access Office Login to your office 365 using <a href='https://login.microsoftonline.com/'>This Link </a>"
$EmailBody += "</body></html>"
 
echo $EmailBody
echo $Users
# Merge: Conduct the email merge, sending emails (remove -WhatIf)
Send-MailMessage -To $EmailTo -From $EmailFrom -Subject $EmailSubject -Body $EmailBody -BodyAsHTML -SmtpServer $EmailSmtpServer -DeliveryNotificationOption $EmailDeliveryNotificationOption

30 Ekim 2015 Cuma

Moodle Adding Event Monitor Rules in Bulk to all of the Courses

Event Monitor Rules feature is a new and a missing feature which has arrived to moodle in version 2.8. This feature help students to be informed by email if a course material added updated or deleted etc. So they do not need to login to check whether a content has been added to the course or not. It also informs teachers and admins about  a specific event occurred (a course has been added, a content has been viewed etc.).

But if you are administering a moodle with 150+ courses it is real heavy duty task to add rules one by one to every course created in moodle.

So with the following php code you can add a rule to the every course created in moodle.

$link = mysql_connect('moodle_host_name_or_ip', 'database_username', 'database_password');
//if connection is not successful you will see text error
if (!$link) {
             die('Could not connect: ' . mysql_error());
}
//if connection is successfuly you will see message bellow
echo 'Connected successfully\n';

$type="\\core\\event\\course_module_created";
$content="Course content has been added.
";
$content2="Link : {rulename}
Description: {description}
Event Name: {eventname}
";

$type=mysql_real_escape_string($type);
$content=mysql_real_escape_string($content);
$content2=mysql_real_escape_string($content2);

mysql_select_db('moodle');


//This query finds the courses in moodle
$query_id= "select id from mdl_course";
$result_id = mysql_query($query_id);
echo $result_id;
while($row = mysql_fetch_row($result_id)) {
    echo $row[0];
    echo "\n";
//This below query adds the event monitor rules into he courses.
$query="INSERT INTO mdl_tool_monitor_rules (userid,courseid,name,plugin,eventname,description,
descriptionformat,frequency,timewindow,template,templateformat,timecreated,timemodified) VALUES('2','".$row[0]."',
'Course Content has been added','core','".$type."','".$content."','1','1','60','".$content2."','1','1445596840','1445596840')";
mysql_query($query);
    }
mysql_close($link);

?>
By changing the $type variable you can add any kind of event rules to the moodle.

İzleyiciler