Jump to content

Recommended Posts

Posted

HELP!!!!!!!!!

 

 

 

I'm trying to upload a powershell script i made via Group Policy Management to generate email signatures for Staff via Active Directory, but every time i upload the script on and login, all i get is a black screen and when i remove it, it goes back to normal. I've checked Event Viewer and can't seem to find the source, any one have any ideas????????

 

 

Here's the script below if anyone whose curious:

 

#Custom variables $SignatureName = 'Signature' $SigSource = "\\PREP-AD02\AD Resources$\Signature.docx" #Path to the *.docx file$SignatureVersion = "1.7" #Change this if you have updated the signature. If you do not change it, the script will quit after checking for the version already on the machine $ForceSignature = '1' #Set to 1 if you don't want the users to be able to change signature in Outlook #Environment variables $AppData=(Get-Item env:appdata).value $SigPath = '\Microsoft\Signatures' #Path to signatures. $LocalSignaturePath = $AppData+$SigPath $RemoteSignaturePathFull = $SigSource #Check signature path (needs to be created if a signature has never been created for the profile if (-not(Test-Path -path $LocalSignaturePath)) { New-Item $LocalSignaturePath -Type Directory} #Copy version file If (-not(Test-Path -Path $LocalSignaturePath\$SignatureVersion)) { If (Test-Path HKCU:'\Software\Microsoft\Office\16.0') { $ForceKeyPathReply = (Get-ItemProperty 'HKCU:\Software\Microsoft\Office\16.0\Common\MailSettings').ReplySignature -eq $null $ForceKeyPathNew = (Get-ItemProperty 'HKCU:\Software\Microsoft\Office\16.0\Common\MailSettings').NewSignature -eq $null If ($ForceKeyPathReply -eq $False) {Remove-ItemProperty -path 'HKCU:\Software\Microsoft\Office\14.0\Common\MailSettings' -name ReplySignature} Else {Write-Host "The reg value does not exist"} If ($ForceKeyPathNew -eq $False) {Remove-ItemProperty -path 'HKCU:\Software\Microsoft\Office\14.0\Common\MailSettings' -name NewSignature} Else {Write-Host "The reg value does not exist"} } If ($ForceSignature -eq '1') { Get-ChildItem -Path $LocalSignaturePath -Recurse | foreach {remove-item $_.fullname -recurse -force -ErrorAction SilentlyContinue} } New-Item -Path $LocalSignaturePath\$SignatureVersion -ItemType Directory } Elseif (Test-Path -Path $LocalSignaturePath\$SignatureVersion) { break } #Get Active Directory information for current user $UserName = $env:username $Filter = "(&(objectCategory=User)(samAccountName=$UserName))" $Searcher = New-Object System.DirectoryServices.DirectorySearcher $Searcher.Filter = $Filter $ADUserPath = $Searcher.FindOne() $ADUser = $ADUserPath.GetDirectoryEntry() $ADDisplayName = $ADUser.DisplayName $ADEmailAddress = $ADUser.mail $ADTitle = $ADUser.title $ADTelePhoneNumber = $ADUser.TelephoneNumber $ADModify = $ADUser.whenChanged #Copy signature templates from source to local Signature-folder Write-Output "Copying Signatures" Copy-Item "$Sigsource" $LocalSignaturePath -Recurse -Force $ReplaceAll = 2 $FindContinue = 1 $MatchCase = $False $MatchWholeWord = $True $MatchWildcards = $False $MatchSoundsLike = $False $MatchAllWordForms = $False $Forward = $True $Wrap = $FindContinue $Format = $False #Insert variables from Active Directory to rtf signature-file $MSWord = New-Object -ComObject word.application $fullPath = $LocalSignaturePath+'\'+$SignatureName+'.docx' $MSWord.Documents.Open($fullPath) #User Name $FindText = "DisplayName"$ReplaceText = $ADDisplayName.ToString()$MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord, $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap, $Format, $ReplaceText, $ReplaceAll ) #Title $FindText = "Title" $ReplaceText = $ADTitle.ToString() $MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord, $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap, $Format, $ReplaceText, $ReplaceAll ) #Email Address $FindText = "e-mail" $ReplaceText = $ADEmailAddress.ToString() $MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord, $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap, $Format, $ReplaceText, $ReplaceAll ) #Save new message signature Write-Output "Saving signatures"#Save HTML $saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatHTML"); $path = $LocalSignaturePath+'\'+$SignatureName+".htm" $MSWord.ActiveDocument.saveas([ref]$path, [ref]$saveFormat) #Save RTF $saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatRTF"); $path = $LocalSignaturePath+'\'+$SignatureName+".rtf" $MSWord.ActiveDocument.SaveAs([ref] $path, [ref]$saveFormat) #Save TXT $saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatText"); $path = $LocalSignaturePath+'\'+$SignatureName+".txt" $MSWord.ActiveDocument.SaveAs([ref] $path, [ref]$SaveFormat) $MSWord.ActiveDocument.Close() $MSWord.Quit() #Office 2016 signature If (Test-Path HKCU:Software\Microsoft\Office\16.0) { If ($ForceSignature -eq '0') { $ForceKeyPathReply = (Get-ItemProperty 'HKCU:\Software\Microsoft\Office\16.0\Common\MailSettings').ReplySignature -eq $null $ForceKeyPathNew = (Get-ItemProperty 'HKCU:\Software\Microsoft\Office\16.0\Common\MailSettings').NewSignature -eq $null If ($ForceKeyPathReply -eq $False) {Remove-ItemProperty -path 'HKCU:\Software\Microsoft\Office\16.0\Common\MailSettings' -name ReplySignature} Else {Write-Host "The reg value does not exist"} If ($ForceKeyPathNew -eq $False) {Remove-ItemProperty -path 'HKCU:\Software\Microsoft\Office\16.0\Common\MailSettings' -name NewSignature} Else {Write-Host "The reg value does not exist"} $MSWord = New-Object -comobject word.application $EmailOptions = $MSWord.EmailOptions $EmailSignature = $EmailOptions.EmailSignature $EmailSignatureEntries = $EmailSignature.EmailSignatureEntries $EmailSignature.NewMessageSignature=$SignatureName $EmailSignature.ReplyMessageSignature=$SignatureName $MSWord.Quit() } If ($ForceSignature -eq '1') { $MSWord = New-Object -comobject word.application $EmailOptions = $MSWord.EmailOptions $EmailSignature = $EmailOptions.EmailSignature $EmailSignatureEntries = $EmailSignature.EmailSignatureEntries $EmailSignature.NewMessageSignature=$SignatureName $EmailSignature.ReplyMessageSignature=$SignatureName $MSWord.Quit() If (Get-ItemProperty -Name 'NewSignature' -Path HKCU:'\Software\Microsoft\Office\16.0\Common\MailSettings') { } Else { New-ItemProperty HKCU:'\Software\Microsoft\Office\16.0\Common\MailSettings' -Name 'NewSignature' -Value $SignatureName -PropertyType 'String' -Force } If (Get-ItemProperty -Name 'ReplySignature' -Path HKCU:'\Software\Microsoft\Office\16.0\Common\MailSettings') { } Else { New-ItemProperty HKCU:'\Software\Microsoft\Office\16.0\Common\MailSettings' -Name 'ReplySignature' -Value $SignatureName -PropertyType 'String' -Force } } }

Posted

Call the powershell script via a batch file, if you want it completely invisible use a vbs script instead.

 

Batch file will look like this:

 

%SystemRoot%\syswow64\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File "FILE LOCATION"

  • Thanks 1
Posted

The below is all you put in a .bat batch file, you just need to enter the location of the .ps1 PowerShell script file. All should work fine as long as the PowerShell scripting is good. Does it work okay if you open PowerShell as the user and enter in the PowerShell script contents?

 

%SystemRoot%\syswow64\WindowsPowerShell\v1.0\power shell.exe -ExecutionPolicy Bypass -File "FILE LOCATION"

Posted

We use a VBS script that runs as a logon script in Group Policy Manager, this way we don't need to change it for different types of Outlook.

 

 

 

On Error Resume NextSet objSysInfo = CreateObject("ADSystemInfo")strUser = objSysInfo.UserName Set objUser = GetObject("LDAP://" & strUser)strName = objUser.FullName strTitle = objUser.Title strInitials = objUser.initialsstrFirstName = objUser.FirstNamestrLastName = objUser.LastNamestrDepartment = objUser.Department strCompany = objUser.Company strPhone = objUser.telephoneNumber strMobile = objUser.mobile

 

' Make text file in users home dir to allow them to add what book they are reading

Set objFSO=CreateObject("Scripting.FileSystemObject")strCurrentlyReadingFile = "N:\!CurrentlyReading.txt"If objFSO.FileExists(strCurrentlyReadingFile) ThenElseSet objFileToMake = objFSO.CreateTextFile(strCurrentlyReadingFile,True)objFileToMake.Write "Please type the name of the book you are currently reading in the line below." & vbCrLfobjFileToMake.CloseSet objFileToMake = NothingEnd IfConst ForReading = 1Set objFileToRead = objFSO.OpenTextFile(strCurrentlyReadingFile, ForReading)For i = 1 to 1objFileToRead.ReadLineNextstrCurrentlyReading = objFileToRead.ReadLineobjFileToRead.CloseSet objFileToRead = NothingSet objWord = CreateObject("Word.Application")Set objDoc = objWord.Documents.Add() Set objSelection = objWord.SelectionSet objEmailOptions = objWord.EmailOptions Set objSignatureObject = objEmailOptions.EmailSignatureSet objSignatureEntries = objSignatureObject.EmailSignatureEntriesobjSelection.Style = "No Spacing"objSelection.Font.Bold = TrueobjSelection.Font.Name = "Arial"objSelection.Font.Size = 12objSelection.Font.Color = RGB(0,0,0)'InitialsIf strInitials = "" ThenElsestrInitials = strInitials & " "End If'First NameIf strFirstName = "" ThenElsestrFirstName = strFirstName & " "End If'Last NameIf strLastName = "" ThenElsestrLastName = strLastName & " "End If'Full NameobjSelection.Font.Bold = TrueobjSelection.TypeText strInitials & strFirstName & strLastName & vbLFobjSelection.Font.Bold = False'Job TitleIf strTitle = "" ThenElseobjSelection.TypeText strTitle & vbLFEnd If'DepartmentIf strDepartment = "" ThenElseobjSelection.TypeText strDepartment & vbLFEnd IfobjSelection.TypeText vbLF'Direct NumberIf strPhone = "" ThenElseobjSelection.Font.Bold = TrueobjSelection.TypeText "Direct: "objSelection.Font.Bold = FalseobjSelection.TypeText strPhone & vbLFEnd If'I am currently readingIf strCurrentlyReading = "" ThenElseobjSelection.Font.Name = "Arial"objSelection.Font.Size = 12objSelection.Font.Color = RGB(0,0,0)objSelection.Font.Bold = TrueobjSelection.TypeText "I am currently reading: "objSelection.Font.Bold = FalseobjSelection.TypeText strCurrentlyReading & vbLFEnd If'comment out the next lines to remove "Respect the work-life balance"objSelection.Font.Bold = FalseobjSelection.Font.Name = "Arial"objSelection.Font.Size = 10objSelection.Font.Color = RGB(0,170,240)objSelection.TypeText vbLFobjSelection.TypeText "Schools Name respects the work-life balance of its staff, who are not expected to read or respond to emails outside of their working hours."objSelection.TypeText vbLF & vbLF'comment out to remove school logo and address.objSelection.Font.Bold = FalseobjSelection.Font.Name = "Georgia"objSelection.Font.Size = 10objSelection.Font.Color = RGB(0,0,0)Set colShapes = objDoc.ShapesSet objShape = objSelection.InlineShapes.AddPicture("https://schoolsname.sch.uk/EMailFooter/Signature.jpg")Set objSelection = objDoc.Range()objSignatureEntries.Add "AD Signature", objSelection objSignatureObject.NewMessageSignature = "AD Signature"objSignatureObject.ReplyMessageSignature = "AD Signature"objDoc.Saved = True objWord.Quit

Posted (edited)

No. You only need to enter the location of your .ps1 file after the -File switch, I've put an example location in

 

%SystemRoot%\syswow64\WindowsPowerShell\v1.0\power shell.exe -ExecutionPolicy Bypass -File "C:\SignatureScript.ps1"

 

Put that into a batch file, run it normally as the user, not as an Admin.

Edited by thimon
  • Thanks 1
  • 3 weeks later...
Posted
No. You only need to enter the location of your .ps1 file after the -File switch, I've put an example location in

 

%SystemRoot%\syswow64\WindowsPowerShell\v1.0\power shell.exe -ExecutionPolicy Bypass -File "C:\SignatureScript.ps1"

 

Put that into a batch file, run it normally as the user, not as an Admin.

 

So i've put the batch file path on the GPO and i've logged in as a normal user expecting it to just run as normal. The expected result is that it should have run the script on startup and generated the signature but nothing's appeared when i click on the Signature section in Outlook.

 

Any advice would be greatly appreciated.

Posted
[ATTACH]56715[/ATTACH] When testing, I didn't need any Parameters set, what I did do was put the ps1 file into the PowerShell folder for that GPO. (Clicking Show Files and pasting the ps1 file in that folder)

 

Thanks for the tip.

 

Just out of curiosity what was your end result????? did Outlook generate a signature for you?????

 

At the moment, i've got these files stored in a hidden share atm i'm generating the signature from there locally to my PC for testing purposes, should i move these files to the powershell folder as well?

docs.PNG

Posted

Outlook did generate a signature for me, I had the file in the same folder and had ".\Signature.docx" set in path but you should also be able to have it set to a share too "\\ShareName\Share$\Signature.docx".

Have you been changing the $SignatureVersion number every time you save the file? if you don't it will just ignore any changes you have made.

  • Thanks 1
Posted
Outlook did generate a signature for me, I had the file in the same folder and had ".\Signature.docx" set in path but you should also be able to have it set to a share too "\\ShareName\Share$\Signature.docx".

Have you been changing the $SignatureVersion number every time you save the file? if you don't it will just ignore any changes you have made.

 

ah, i didn't think i had to because i wasn't changing the code directly, i'll change the version number and see how that goes.

Posted
Outlook did generate a signature for me, I had the file in the same folder and had ".\Signature.docx" set in path but you should also be able to have it set to a share too "\\ShareName\Share$\Signature.docx".

Have you been changing the $SignatureVersion number every time you save the file? if you don't it will just ignore any changes you have made.

 

This is the story so far:

 

ps1.PNG

file path.PNG

 

I've even changed the Version in the code itself, the script runs fine but the Signature's not appearing. Is there anything i'm missing in particular?????

Posted

You don't need to have the Signature.docx setting in the script tab.

The bit you need to link to the Signature.dox file is in the PS1 file at the top

 

$SigSource = "C:\AD Resources\Signature.docx" #Path to the *.docx file

or if it is in the same folder as the ps1 file

$SigSource = ".\Signature.docx" #Path to the *.docx file

 

What have you got in the Signature.docx file? the links are case sensitive ( DisplayName Title e-mail )

 

and don't forget to edit the Version Number every time you change the Signature.docx or Signature.ps1 file

 

$SignatureVersion = "1.24"

Posted
You don't need to have the Signature.docx setting in the script tab.

The bit you need to link to the Signature.dox file is in the PS1 file at the top

 

$SigSource = "C:\AD Resources\Signature.docx" #Path to the *.docx file

or if it is in the same folder as the ps1 file

$SigSource = ".\Signature.docx" #Path to the *.docx file

 

What have you got in the Signature.docx file? the links are case sensitive ( DisplayName Title e-mail )

 

and don't forget to edit the Version Number every time you change the Signature.docx or Signature.ps1 file

 

$SignatureVersion = "1.24"

 

 

Inside the Signature.docx file is my template of the signature itself with the variable (DisplayName Title e-mail)

 

I've tried to put in one of the changes ($SigSource = ".\Signature.docx" #Path to the *.docx file) changing it word-for-word on the powershell script and changing the version and the script runs when i log in keep getting these kind of errors (so bizarre).

 

I'm pretty sure that i've missed something key, i can't put my finger on it (was never good at writing scripts at university :rant:)

 

What's you take??????????

IMG_20200213_151144.jpg

IMG_20200213_151154.jpg

IMG_20200214_100202.jpg

IMG_20200214_122655.jpg

IMG_20200214_145123.jpg

Posted
That looks like there is a issue with the way your profiles are setup and trying to save the normal.dotm, we had this issue with sims once. will have a look at our logs on monday to see what i did.
  • Thanks 1
Posted
That looks like there is a issue with the way your profiles are setup and trying to save the normal.dotm, we had this issue with sims once. will have a look at our logs on monday to see what i did.

 

You're too kind, THANK YOU SO MUCH, sorry to be a bother :dizzy:

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...