Skip to content

Instantly share code, notes, and snippets.

@melvinpetix
Last active November 17, 2022 17:38
Show Gist options
  • Save melvinpetix/0e1488146addc9af84159ce58eddbc64 to your computer and use it in GitHub Desktop.
Save melvinpetix/0e1488146addc9af84159ce58eddbc64 to your computer and use it in GitHub Desktop.
<#
Name = mtr.psm1
Author = Melvin Biscarra
Description = Powershell modules for NN Meeting Room Project
#>
function Set-OnlinePRofile{
PARAM (
[string]$upn
)
$name=$upn.Split("@")[0]
$domain=$upn.Split("@")[1]
$O365CREDS = GetSecuredCredential
connect-MsolService -Credential $O365CREDS
try {
if($domain -match ".onmicrosoft."){
Set-MsolUser -UserPrincipalName $name@novonordisk.com -PasswordNeverExpires $true
Set-MsolUserPrincipalName -UserPrincipalName $name@novonordisk.onmicrosoft.com -NewUserPrincipalName $name@novonordisk.com
}
else {
Set-MsolUserPrincipalName –UserPrincipalName $upn –NewUserPrincipalName "$name@novonordisk.onmicrosoft.com"
Set-MsolUser -UserPrincipalName -BlockCredential $false
Set-MsolUser -UserPrincipalName $name@novonordisk.com -PasswordNeverExpires $true
Set-MsolUserPrincipalName –UserPrincipalName $name@novonordisk.onmicrosoft.com –NewUserPrincipalName $upn
}
}
catch {
throw $_
}
}
function Random-Password {
PARAM (
[Int32]$Length = 12,
[Int32]$SpecialChar = 5,
[Int32]$Count = 1
)
BEGIN {
Add-Type -AssemblyName System.web;
}
PROCESS {
1..$Count | ForEach-Object -Process {
[System.Web.Security.Membership]::GeneratePassword($Length, $SpecialChar)
}
}
}
function Send-Email{
PARAM (
[string]$To,
[string]$From,
[string]$Subject,
[String]$Body
)
$paramSendMail = @{
SmtpServer = 'mailrelay.novonordisk.com'
To = $To
From = 'noreply@novonordisk.com'
Subject = $SUbject
Body = 'Meeting Room $name password: $newpassword'
}
Send-MailMessage @$paramSendMail
}
function Create-MTRMailbox{
Write-Host "Creating Mailbox Account"
$parmNewMailbox = @{
Name = $name
Alias = $alias
Room = $true
EnableRoomMailboxAccount = $true
MicrosoftOnlineServicesID = $onlineId
RoomMailboxPassword = (ConvertTo-SecureString -String $password -AsPlainText -Force)
}
New-Mailbox @paramNewMailbox
}
function GetSecuredCredential(){
$pass = cat ".\Psscript\365secure.txt" | Convertto-securestring
return new-object -typename System.Management.Automation.PSCredential -argumentlist "autouserw2k@corp.novocorp.net", $pass
}
function GetCredential{
param([string]$type)
$Error.Clear();
$pass = cat ".\PSScript\365secure.txt" | Convertto-securestring
$365CREDS = New-Object -typename System.Management.Automation.PsCredential -argumentlist autouserw2k@novonordisk.com, $pass
$UserCredential= New-Object System.Management.Automation.PsCredential("corp\autouserw2k",$pass)
try{
switch($type){
"OnPremise"{
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://NNEXMRDK101.corp.novocorp.net/powershell -Authentication Kerberos -Credential $UserCredential
Import-PSSession $Session -AllowClobber|Out-Null;
}
"Office365"{
Connect-ExchangeOnline -Credential $365CREDS -ShowBanner:$false
}
"MsOnline" {
Connect-Msolservice -Credential $365CREDS -ShowBanner:$false
}
"Skype"{
$SkypeOnline = New-CSOnlineSession -Credential $UserCredential
Import-PSSession $SkypeSession
}
}
} catch{
echo $switch error
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment