I have a script that creates a .htm and .txt file in the %appdata%\Microsoft\Signatures folder.
I set the signature via registry using:
NEW-ITEMPROPERTY HKCU:'\Software\Microsoft\Office\15.0\Common\MailSettings' -Name 'NewSignature' -Value $SignatureName -PropertyType 'String' -Force
NEW-ITEMPROPERTY HKCU:'\Software\Microsoft\Office\15.0\Common\MailSettings' -Name 'ReplySignature' -Value $SignatureName -PropertyType 'String' -Force
Everything appears to work except the signature does not show in the compose window by default. It will let me add it manually.
If I open up the signature settings area within Outlook, make zero changes (I couldn't if I wanted as it is greyed out) and then close it, the signature starts showing automatically in emails again.
What am I missing? What does opening then closing the signature window do?
You can use functions within Word to set default signature for new e-mails and replies. Try this:
$Word = New-Object -ComObject Word.Application
$EmailOptions = $Word.EmailOptions
$Signature = $EmailOptions.EmailSignature
$Signature.NewMessageSignature = $SignatureName
$Signature.ReplyMessageSignature = $SignatureName
$Word.Quit()
Should anyone else come into this issue it was solved by deleting a registry entry.
REMOVE-ITEMPROPERTY -path "HKCU:\Software\Microsoft\Office\15.0\Outlook\Setup\" -name "First-Run"
Adding this in and having it run while Outlook is closed fixed the issue
Related
I want a powershell script to run each time a user login to Windows by placed in: Shell:common startup.
This script must add about 50 Regkey's in HKCU, which is setting/path for Presetfolders for a application.
I want to use Powershell and have tried this command adding the RegKey (This command needs to be repeated for each 50 regkeys!):
New-ItemProperty -Path 'HKCU:\Software\AppName' -Name 'PresetFolder' -PropertyType String -Value '$env:userprofile\Documents\AppName\Presets1' -Force
New-ItemProperty -Path 'HKCU:\Software\AppName' -Name 'PresetFolder' -PropertyType String -Value '$env:userprofile\Documents\AppName\Presets2' -Force .......
When using "$env:userprofile" instead of c:\Users\MyUserProfile\Documents\.... the -value in the RegKey will be: "$env:userprofile\Documents\NewFolder\Presets" and not as wanted: "c:\Users\MyUserProfile\Documents\NewFolder\Presets".
I need a Variable for each userprofile!
Alternatively I can after Program installation by using admin-account, I can exported all RegKey's as a .reg-file. Before using the powershell-script to merge the RegKeys everytime a user is logging in Windows, I now need to search and replace the value of the path (-Value) from AdminUserProfil-path into a variable for each user running the script.
Part of the Reg-file:
[HKEY_CURRENT_USER\Software\AppName\Version]
"HelpDocPath"="C:\Users\\AdminUserprofiles\\Documents\\AppName\\Version\\HTML Help\\en"
"ExciterCacheInstallPath"="C:\\Program Files\\AppName\\Version\\Exciter Cache"
"DSPResourceFilesInstallPath"="C:\\Program Files\\AppName\\Version/Resources"
"InstallPath"="C:\\Program Files\\AppName\\InstallFolder"
"PresetFolder"="C:\\Users\\AdminUserprofiles\\Documents\\AppName\\Version\\Presets\\Global Presets"\
Hope anyone can help?
What do I need to type for the right path, so each user will have there own path? Do I need a variable fo rusers or..?
Thank you.
Define $env:USERPROFILE as a variable so you can call it, otherwise PS will just output what you have typed, which is what is happening in this case.
$path = "$env:USERPROFILE"
New-ItemProperty -Path 'HKCU:\Software\AppName' -Name 'PresetFolder' -PropertyType String -Value '$path\Documents\AppName\Presets1' -Force
Hello Stack overflow community, for a security class, I'm trying to replicate a "bad" usb being plugged in and then sending a generated text file to a recipient via outlook.
I will say I am a PowerShell novice by all means so this may be something simple that I just don't understand.
I cannot get the relative path for $var1 to work.
When I use an absolute path to the generated file it sends the attachment fine.
I'm trying to use the Get-ChildItem e:\ -filter "*.txt" to populate this variable dynamically, but when it gets to the .Attchments.Add($var1) it breaks with Error while invoking Add. Could not find member.
Meanwhile, the .Count function on it does return a 1 signifying that the file is there.
I could not find a good indication of what this error means. Googling the error results in Microsoft documentation and nothing as it relates to programming in Powershell. I've tried messing with ''s around the Get-ChildItem statement and various other syntactical tweaks. I haven't found a good alternative to the way we've decided to send the email thus far. Securing SMTP for this isn't practical as it wouldn't fit the scenario.
New-Item -Path E:\ -Name "DynamicNameOfPC" -ItemType "file" -Value "Test"
(Get-ChildItem e:\ -filter "*.txt").Count
$var1 = Get-ChildItem e:\ -filter "*.txt"
$OL = New-Object -ComObject outlook.application
Start-Sleep 5
#Create Item
$mItem = $OL.CreateItem("olMailItem")
$mItem.To = "Test#test.com"
$mItem.Subject = "Testing Script"
$mItem.Body = "Testing"
$mItem.Attachments.Add($var1)
$mItem.Send()
`
Through analysis with a random user on a Discord, We were able to realize the Get-ChildItem was getting the file name but not the full path.
Adding a variable with the path of E:\ before $var1 got it working perfectly.
I'm trying to use a PowerShell script to change the home page of IE 11 on a computer. Everything I've read online shows the same script, but when I execute it, it is not changing the value in the registry. Can someone help me troubleshoot what's wrong?
write "Setting google as IE homepage..."
$path = 'HKCU:\Software\Microsoft\Internet Explorer\Main\'
$name = 'start page'
$value = 'http://www.google.com/'
Set-Itemproperty -Path $path -Name $name -Value $value
You must confirm the bottom message when you open IE
I'm writing my first powershell script and I'm having a little trouble.
Up to this point my system creates a directory tree and populates it with files. The final step is to put a shortcut on my desktop.
I've come up with the code below:
$ShortcutFile = "$home\Desktop\" + $protocol + ".lnk"
If ( (test-path -path "$ShortcutFile") -ne $true)
{
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutFile)
$Shortcut.TargetPath = $root_path
$Shortcut.Save()
}
This doesn't work as I'm sure any experienced powershell user knows. A file is created rather than a directory. I imagine the correct way to fix this is to change one of the object members in WScript.Shell which control's the file type. I have had no luck locating any resources on how to do this specifically, or any other way to go about doing it. I found the API on the MSDN website but there where only a few members listed. There must be more.
What is the best way to accomplish this?
Thanks
New-Item -itemtype symboliclink -Path "PathWhereYouWantToPutShortcut" -name "NameOfShortcut" -value "PathOfWhatYourTryingToLinkTo"
New-Item Documentation
Assuming that you mean the shortcut type is a File rather than a File folder then a workaround is to make an Application launcher instead, which always works.
I originally found this solution here.
$wsshell = New-Object -ComObject WScript.Shell
$lnk = $wsshell.CreateShortcut($ShortcutFile)
$lnk.WindowStyle = 1
$lnk.TargetPath = "explorer.exe"
$lnk.Arguments = $TargetPath
$lnk.IconLocation = "explorer.exe,0"
$lnk.save() # This will overwrite the previous link if it existed
I experienced this when creating a shortcut to a directory that didn't exist. If I simply created the directory ahead of time, then the shortcut worked correctly.
I'm interested in adding a property to my files under a certain scope that contains their current locations in my file system, in order to track file movement. I would think that this could be done with New-ItemProperty, with a command similar to the following:
Get-ChildItem -recurse | foreach { New-ItemProperty -Path $.FullName -Name "OriginalLocation" -PropertyType string -Value $.FullName }
However, when I try this, I'm spammed with the following error:
New-ItemProperty : Cannot use interface. The IDynamicPropertyCmdletProvider interface is not implemented by this provider.
After some searching, it appears that New-ItemProperty is all but useless except for working with the registry. Fine. Windows has myriad other file properties I should be able to hijack in order to get this done. "Label" and "Tags" come to mind. So let's try setting those via Set-ItemProperty instead.
Set-ItemProperty : Property System.String Label=D:\test\file.txt does not exist.
It appears I need to create these properties after all. Is this a shortcoming of New-ItemProperty? Maybe setting properties such as this on arbitrary items is some WMI thing I don't know about?
Here is my solution using the redirections ('<' & '>') that allow to manipulate alternate data stream in CMD.EXE. It works in Powershell without any extentions
# AlternateDataStream.ps1
$scriptBlockSetStream = {cmd /C `"echo $($Args[0])`>$($Args[1]):$($Args[2])`"}
$scriptBlockGetStream = {cmd /C `"more `<$($Args[0]):$($Args[1])`"}
$streamName = "NativeFilePath"
$File = "C:\Temp\ADSTest\toto.txt"
$streamContent = Split-Path -Path $File -Parent
# Set the data stream
Invoke-Command -ScriptBlock $scriptBlockSetStream -ArgumentList $streamContent,$File,$streamName
# Get the Data Stream
$res = Invoke-Command -ScriptBlock $scriptBlockGetStream -ArgumentList $File,$streamName
$res
Another option might be to use alternate data streams to store your path. If you are running PowerShell 3.0, you can manipulate them quite easily. Based on the first article, you would have something resembling:
"echo test" | out-file c:\powershell\test.ps1
$fs = new NTFS.FileStreams('c:\powershell\test.ps1')
$fs.add('OriginalPath')
$stream = $fs.Item('OriginalPath').open()
$sw = [System.IO.streamwriter]$stream
$sw.writeline('<path>')
$sw.close()
$stream.close()