# -----------------------------------------------
# * WelcomeNewCompany v1 20180918 created by *
# * Eric Wilborn / ericwilborn@gmail.com.com *
# * Creates AzureAD group and populates with *
# * external users (from CSV), sends invites, *
# * and adds the AzureAD group to the *
# * visitors group of SharePoint Online site *
# * that has already been created. *
# * Requires populated CSV with Name, Email as *
# * header, located in root of C:\ (or change *
# * $csv variable location) *
# -----------------------------------------------
#Import SharePoint Online Module
Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
#Provide Credentials
$credential=Get-Credential
#Request SPO domain
$domain=Read-Host 'Enter domain of SharePoint Online site, IE: https://EXAMPLE.sharepoint.com'
#Connect to Azure and SharePoint Online
Connect-AzureAD -Credential $credential
Connect-SPOService -Url https://$domain-admin.sharepoint.com -credential $credential
#Request name of site to work with
$SiteName=Read-Host 'Enter site, IE: https://domain.sharepoint.com/sites/EXAMPLE'
#Set full URL of site
$FullSite="https://$domain.sharepoint.com/sites/$SiteName"
#Create group in AzureAD and get ID
$GroupID=(New-AzureADMSGroup -description "Visitors for SharePoint Online Site - $SiteName" `
-displayname $SiteName -mailenabled 0 -mailnickname $SiteName -SecurityEnabled 1).ID
#Pause 30 seconds for the AzureAD group to be available
Start-Sleep 30
#Add AzureADGroup to SharePoint Visitors Group
Add-SPOUser -site $FullSite -LoginName $SiteName -Group "$SiteName Visitors"
#Link to CSV file with Name in first column, Email in second column
$csv=Import-Csv C:\WelcomeNewCompany.csv
#for each line in CSV, do the following
foreach ($line in $csv) {
#Invite user (with email invitation) and get ID
$userID=(New-AzureADMSInvitation -InvitedUserDisplayName $line.Name -InvitedUserEmailAddress $line.Email `
–InviteRedirectURL $FullSite -SendInvitationMessage 1).invitedUser.ID
#Add new user to group
Add-AzureADGroupMember -ObjectID $GroupID -RefObjectID $userID
}
#Loads SP shell if not already loaded
Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
Function SPCopyAlerts($SiteURL, $SourceUserAccount, $TargetUserAccount)
{
#Get the Site
$Site = Get-SPSite $SiteURL
#Check each web in SharePoint site collection
foreach($web in $site.AllWebs)
{
#Resolve users
$SourceUser=$web.EnsureUser($SourceUserAccount)
$TargetUser = $web.EnsureUser($TargetUserAccount)
#Collect alerts from the source user
$SourceAlertCollection=$SourceUser.Alerts
#loop through alerts of source user, copy to target user
foreach($SourceAlert in $SourceAlertCollection)
{
Write-host "Copying Alert from: $($Web.Url)/$($SourceAlert.ListUrl)"
$NewAlert = $TargetUser.Alerts.Add()
$NewAlert.Title = $SourceAlert.Title
$NewAlert.AlertType = $SourceAlert.AlertType
$NewAlert.User = $TargetUser
$NewAlert.List = $SourceAlert.List
$NewAlert.DeliveryChannels = $SourceAlert.DeliveryChannels
$NewAlert.EventType = $SourceAlert.EventType
$NewAlert.AlertFrequency = $SourceAlert.AlertFrequency
$NewAlert.Update()
}
}
}
#SET THESE VARIABLES
$SiteURL="ENTER URL OF SHAREPOINT SITE HERE"
$SourceUserAccount="domain\SOURCE"
$TargetUserAccount ="domain\TARGET"
#Call function to perform the work
SPCopyAlerts $SiteURL $SourceUserAccount $TargetUserAccount
Save the code below as a .ps1 file on the Domain Controller(s) to monitor
Call the .ps1 from a Scheduled Task, triggering on the Event ID in question
#Set the Event ID
$EventId = 4738
#Change the Logname portion to match the proper log from Event Viewer
$E = Get-WinEvent -MaxEvents 1 -FilterHashTable @{Logname = "Security" ; ID = $EventId}
$Message = $E.Message
$EventID = $E.Id
$MachineName = $E.MachineName
$Source = $E.ProviderName
#Change the domain from COMPANY.com to your company's domain
$EmailFrom = adalerts@COMPANY.com
#Change the email address to a user or distribution group to notify
$EmailTo = USER@COMPANY.com
$Subject ="Alert From $MachineName"
$Body = "EventID: $EventID `n Source: $Source `n MachineName: $MachineName `n Message: $Message"
#Change to valid SMTP server in the domain
$SMTPServer = "smtp.COMPANY.com"
Send-MailMessage -From $EmailFrom -To $EmailTo -Subject $Subject -Body $Body -Priority High -SmtpServer $SMTPServer
---Unlock OneDrive Site
Set-SPOSite -Identity 'https://domain-my.sharepoint.com/personal/username_domain_com' -LockState Unlock
---Return licenses on an account
Get-MsolUser -UserPrincipalName | foreach { $_.Licenses.ServiceStatus }
On the server side:
Download and install proper version of HP DesignJet 5500 series driver for your use
Install the printer as a new device or replace the existing driver on the currently installed printer
and share it out
On the computer side:
Go into Control Panel>Devices and Printers. Right-click on the existing PRINTERNAME on PRINTSERVER
and Remove
Format a link similarly to below, then click on the link - choose Open and confirm any dialogs asking
to trust the installation
\\PRINTSERVER\PRINTERNAME
Open AutoCAD and, in the AutoCAD command line, type PLOTTERMANAGER
Double-click the Add-A-Plotter Wizard
Click Next, choose My Computer, click Next, select Hewlett-Packard in the left column, and Select
DesignJet 750C Plus C4709B in the right column
Click Continue in the HP DesignJet “warning” window
Next, choose the listing for the \\PRINTSERVER\PRINTERNAME you recently installed, then click Next
Name plotter as HP DesignJet 1050C, Next
Click Next through the end, and finally click Finish
Navigate to User Configuration>Policies>Windows Settings>Scripts (Logon/Logoff) and double-click Logon.
Click Show Files in the Logon Properties window. Create or edit a batch file (if already present) and paste in the
following contents:
-----------------------------------------------------------------------------------------------------------------------
rem Console Lock Display Off Timeout on battery, set to 45 minutes
powercfg /SETDCVALUEINDEX SCHEME_CURRENT 7516b95f-f776-4464-8c53-06167f40cc99 8EC4B3A5-6868-48c2-BE75-4F3044BE88A7 2700
rem Console Lock Display Off Timeout plugged in, set to 45 minutes
powercfg /SETACVALUEINDEX SCHEME_CURRENT 7516b95f-f776-4464-8c53-06167f40cc99 8EC4B3A5-6868-48c2-BE75-4F3044BE88A7 2700
rem Unattended Sleep Timeout on battery, set to 45 minutes
powercfg /SETDCVALUEINDEX SCHEME_CURRENT 238C9FA8-0AAD-41ED-83F4-97BE242C8F20 7bc4a2f9-d8fc-4469-b07b-33eb785aaca0 2700
rem Unattended Sleep Timeout plugged in, set to 45 minutes
powercfg /SETACVALUEINDEX SCHEME_CURRENT 238C9FA8-0AAD-41ED-83F4-97BE242C8F20 7bc4a2f9-d8fc-4469-b07b-33eb785aaca0 2700
-----------------------------------------------------------------------------------------------------------------------
Modify the time values at the end of each line (shown in seconds) to values appropriate for your setup. I was working with
a screensaver that didn't kick in for 20 minutes of inactivity, thus the large values.
For best results run a gpupdate /force and then log off of the user account and log back in.
Copyright Eric Wilborn; 2022:MMXXII