Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- .SYNOPSIS
- This script import a csv file to .
- .DESCRIPTION
- This script import a csv file containing users informations to create pre-constructed letter for each user.
- Much like Outlook Publipostage.
- .PARAMETER CsvPath
- Used to specify the path of the Csv file.
- .PARAMETER LetterPath
- Used to specify the path of the letter type file.
- .PARAMETER OutPutType
- Used to specify the type of out put desired.
- It can be TextFile or Mail.
- .PARAMETER OutPutPath
- Used to specify the path of the out put files.
- .EXAMPLE
- .\publiPostWin7.ps1 -CsvPath ".\win7users.csv" -LetterPath ".\win7-users.txt"
- .\publiPostWin7.ps1 -CsvPath ".\win7users.csv" -LetterPath ".\win7-users.txt" -OutPutType Mail
- #>
- param
- (
- [string]$CsvPath = "NotSet",
- [string]$LetterPath = "NotSet",
- [string]$OutPutType = "TextFile",
- [string]$OutPutPath = ".\"
- )
- if($CsvPath -eq "NotSet")
- {
- Write-Host "CSV file path not entered"
- Exit
- }
- if($LetterPath -eq "NotSet")
- {
- Write-Host "Letter file path not entered"
- Exit
- }
- $CsvFile = Import-Csv $csvPath
- $cred = Get-Credential
- $cred = Get-StoredCredential -Target myWinStoredPassword
- Foreach($user in $CsvFile)
- {
- $Letter = get-content $LetterPath
- $Letter = $Letter.replace("@Name@", "$($user.UserName)")
- $Letter = $Letter.replace("@machineName@", "$($user.machineName)")
- if($OutPutType -eq "TextFile")
- {
- $FileName = $OutPutPath + "LettreWin7-" + $user.User + ".txt"
- $Letter | Out-File $FileName -Force
- $FileName = $FileName.Remove(0,2)
- Write-Host "$($FileName) created."
- }
- elseif($OutPutType -eq "Mail")
- {
- $FileName = "LettreWin7-" + $user.User
- Send-MailMessage -From "maxime.jolly@domain.fr" -to $user.UserMail -Subject "Mise a jour machine Windows 7" -Body ($Letter | Out-String) -SmtpServer "smtp.domain.fr" -port "587" -UseSsl -Credential $cred
- Write-Host "$($FileName) created."
- }
- else
- {
- Write-Host "Unknown file type specified."
- exit
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement