$smtpServer = "your_smtp_server"
$from = "sender@example.com"
$to = "recipient@example.com"
$subject = "Test Email"
$body = "This is a test email sent via PowerShell."
# Create a MailMessage object
$mailMessage = New-Object System.Net.Mail.MailMessage($from, $to, $subject, $body)
# Create an SmtpClient object
$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
# Send the email
$smtp.Send($mailMessage)
$smtpServer = "your_smtp_server"
$from = "sender@example.com"
$to = "recipient@example.com"
$subject = "Test Email"
$body = "This is a test email sent via PowerShell."
$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($from, $to, $subject, $body)
$smtpServer = "your_smtp_server"
$from = "sender@example.com"
$to = "recipient@example.com"
$subject = "Test Email"
$body = "This is a test email sent via PowerShell."
$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($from, $to, $subject, $body)
****** Script*****
$smtpServer = "your_smtp_server"
$from = "sender@example.com"
$to = "recipient@example.com"
$subject = "Test Email"
$body = "This is a test email sent via PowerShell."
$credentials = Get-Credential
Send-MailMessage -SmtpServer $smtpServer -From $from -To $to -Subject $subject -Body $body -Credential $credentials -UseSsl
# Define email parameters
$from = "sender@example.com"
$to = "recipient@example.com"
$subject = "Test Email"
$body = "This is a test email sent from PowerShell."
$smtpServer = "smtp.example.com" # Replace with your SMTP server address
# Send the email
Send-MailMessage -From $from -To $to -Subject $subject -Body $body -SmtpServer $smtpServer
# Load SharePoint assemblies
Add-Type -Path "# Load SharePoint assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.dll"
# Connect to the SharePoint site
$site = New-Object Microsoft.SharePoint.SPSite("http://yoursharepointserver/sites/yoursite")
$web = $site.OpenWeb()
# Define the document library name
$libraryName = "Your Document Library Name"
# Get the document library
$library = $web.Lists[$libraryName]
# Specify the path to the log file(s)
$logFilePath = "C:\Path\To\Log\File\logfile1.log"
$logFilePath2 = "C:\Path\To\Log\File\logfile2.log"
# Upload the log file(s) to the document library
UploadLogFileToLibrary $library $logFilePath
UploadLogFileToLibrary $library $logFilePath2
Write-Host "Log files uploaded successfully."
# Dispose of objects
$web.Dispose()
$site.Dispose()
# Function to upload a log file to the document library
function UploadLogFileToLibrary {
param (
[Microsoft.SharePoint.SPList]$library,
[string]$logFilePath
)
# Check if the log file exists
if (Test-Path $logFilePath) {
# Open the log file and upload it to the document library
$fileContent = [System.IO.File]::ReadAllBytes($logFilePath)
$fileName = [System.IO.Path]::GetFileName($logFilePath)
$file = $library.RootFolder.Files.Add($fileName, $fileContent, $true)
Write-Host "Log file $($file.Name) uploaded successfully."
} else {
Write-Host "Log file $($logFilePath) does not exist."
}
} Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.dll"# Connect to the SharePoint site
$site = New-Object Microsoft.SharePoint.SPSite("http://yoursharepointserver/sites/yoursite")
$web = $site.OpenWeb()
# Define the document library name
$libraryName = "Your Document Library Name"
# Get the document library
$library = $web.Lists[$libraryName]
# Specify the path to the log file(s)
$logFilePath = "C:\Path\To\Log\File\logfile1.log"
$logFilePath2 = "C:\Path\To\Log\File\logfile2.log"
# Upload the log file(s) to the document library
UploadLogFileToLibrary $library $logFilePath
UploadLogFileToLibrary $library $logFilePath2
Write-Host "Log files uploaded successfully."
# Dispose of objects
$web.Dispose()
$site.Dispose()
# Function to upload a log file to the document library
function UploadLogFileToLibrary {
param (
[Microsoft.SharePoint.SPList]$library,
[string]$logFilePath
)
# Check if the log file exists
if (Test-Path $logFilePath) {
# Open the log file and upload it to the document library
$fileContent = [System.IO.File]::ReadAllBytes($logFilePath)
$fileName = [System.IO.Path]::GetFileName($logFilePath)
$file = $library.RootFolder.Files.Add($fileName, $fileContent, $true)
Write-Host "Log file $($file.Name) uploaded successfully."
} else {
Write-Host "Log file $($logFilePath) does not exist."
}
}
No comments:
Post a Comment