Skip to content

Instantly share code, notes, and snippets.

@ChendrayanV
Created May 8, 2018 10:31
Show Gist options
  • Save ChendrayanV/69324ff835a3d97e5b1c1e3320beec47 to your computer and use it in GitHub Desktop.
Save ChendrayanV/69324ff835a3d97e5b1c1e3320beec47 to your computer and use it in GitHub Desktop.
Demo Web App to Build resume through SharePoint Online information | Node.js , PowerShell and CSOM
Import-Module .\assemblies\Microsoft.SharePoint.Client.dll
Import-Module .\assemblies\Microsoft.SharePoint.Client.UserProfiles.dll
$userName = "chendrayan@contoso.onmicrosoft.com"
$adminPassword = "MySuperPassword" | ConvertTo-SecureString -AsPlainText -Force
$spoCredential = [Microsoft.SharePoint.Client.SharePointOnlineCredentials]::new($userName, $adminPassword)
$spoClientContext = [Microsoft.SharePoint.Client.ClientContext]::new("https://chensoffice365-admin.sharepoint.com")
$spoClientContext.Credentials = $spoCredential
$spoUsers = $spoClientContext.Web.SiteUsers
$spoClientContext.Load($spoUsers)
$spoClientContext.ExecuteQuery()
$spoPeopleManager = [Microsoft.SharePoint.Client.UserProfiles.PeopleManager]::new($spoClientContext)
$collection = @()
foreach ($spoUser in $spoUsers) {
$spoUserProfile = $spoPeopleManager.GetPropertiesFor($spoUser.LoginName)
$spoClientContext.Load($spoUserProfile)
$spoClientContext.ExecuteQuery()
if ($spoUserProfile.Email -ne $null -and $spoUserProfile.UserProfileProperties['FirstName'] -eq 'Chendrayan') {
$result = [pscustomobject]@{
FirstName = $spoUserProfile.UserProfileProperties['FirstName']
LastName = $spoUserProfile.UserProfileProperties['LastName']
DisplayName = $spoUserProfile.UserProfileProperties['PreferredName']
WorkPhone = $spoUserProfile.UserProfileProperties['WorkPhone']
AboutMe = $spoUserProfile.UserProfileProperties['AboutMe']
PictureURL = $spoUserProfile.UserProfileProperties['PictureURL']
JobTitle = $spoUserProfile.UserProfileProperties['SPS-JobTitle']
Skills = ($spoUserProfile.UserProfileProperties['SPS-Skills'] -split "\|")
School = $spoUserProfile.UserProfileProperties['SPS-School']
Interests = ($spoUserProfile.UserProfileProperties['SPS-Interests'] -split "\|")
WorkEmail = $spoUserProfile.UserProfileProperties['WorkEmail']
PastProjects = ($spoUserProfile.UserProfileProperties['SPS-PastProjects'] -split "\|")
}
$collection += $result
}
}
$collection | ConvertTo-Json -Compress
var express = require('express'),
app = express(),
shell = require('node-powershell'),
ps = new shell({
executionPolicy: 'bypass',
noProfile: true
}),
path = require('path');
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
app.get("/", function (request, response) {
response.render('index')
})
app.get("/ResumeVersion1", function (request, response) {
//response.render("present")
ps.addCommand("./scripts/GetSPOUserProfileInformation.ps1")
ps.invoke().then(output => {
var result = JSON.parse(output)
response.render("Version1",{
spoProfileInformation: result
})
})
})
app.listen(3000)
console.log("Its Running!")
doctype html
head
meta(name='viewport', content='width=device-width, initial-scale=1')
style.
body {
font-family: Calibri;
}
/* Style the tab */
.tab {
overflow: hidden;
border: 1px solid #000000;
background-color: #00FA9A;
}
/* Style the buttons inside the tab */
.tab button {
background-color: inherit;
float: left;
border: none;
outline: none;
cursor: pointer;
padding: 14px 16px;
transition: 0.3s;
font-size: 17px;
}
/* Change background color of buttons on hover */
.tab button:hover {
background-color: #00FF00;
}
/* Create an active/current tablink class */
.tab button.active {
background-color: #00FA9A;
}
/* Style the tab content */
.tabcontent {
display: none;
padding: 6px 12px;
border: 1px solid #000000;
border-top: none;
}
h2(style='text-align: center') I ♥ PowerShell
.tab
button.tablinks(onclick="openProfile(event, 'AboutMe')") AboutMe
button.tablinks(onclick="openProfile(event, 'Skills')") Skills
button.tablinks(onclick="openProfile(event, 'Projects')") Projects
#AboutMe.tabcontent
p(style='text-align: center')
img(src=spoProfileInformation.PictureURL)
h3(style='text-align: center') Mobile: #{spoProfileInformation.WorkPhone}
p(style='text-align: center')
a(href="mailto:" + spoProfileInformation.WorkEmail) #{spoProfileInformation.WorkEmail}
h3 AboutMe
p #{spoProfileInformation.AboutMe}
#Skills.tabcontent
h3 Skills
table
tbody
each Skill in spoProfileInformation.Skills
tr
td=Skill
#Projects.tabcontent
h3 Past Projects
table
tbody
each Projects in spoProfileInformation.PastProjects
tr
td=Projects
script.
function openProfile(evt, fieldName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[ i ].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[ i ].className = tablinks[ i ].className.replace(" active", "");
}
document.getElementById(fieldName).style.display = "block";
evt.currentTarget.className += " active";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment