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
Related
So, I'm using Desktop Central to run some scripts on a bunch of machines. The script is supposed to open a zip file in the c:\users%USERNAME%\ folder, and decompress it to a folder of my choosing. The idea is to use a single script for many machines, that can leverage the c:\users\LOGGEDONUSER\downloads folder (Default TEAMS download dir). The idea is that each user will download the archive from teams, and a script will decompress and install from each users DOWNLOADS folder.
The issue is that I don't seem to know how to write a script uses a variable representing the username of the logged in user for the -path in my argument.
For instance;
Extract file
Expand-archive -path $home\Downloads\SWANDPDM_SP5.1.zip -DestinationPath C:\temp\swpdminstaller\extracted\ -Force
#Define registry values to modify to allow for no UAC
$RegistryPath = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System'
$Name = 'ConsentPromptBehaviorAdmin'
$Value = '0'
#Run reg change
New-ItemProperty -Path $RegistryPath -Name $Name -Value $Value -PropertyType DWORD -Force
#Run installer
Invoke-Item C:\temp\swpdminstaller\extracted\SOLIDWORKS_AND_PDM_2021_SP5.1\startswinstall.exe
#Define reg values to change back to default
$RegistryPath = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System'
$Name = 'ConsentPromptBehaviorAdmin'
$Value = '5'
#Run reg change
New-ItemProperty -Path $RegistryPath -Name $Name -Value $Value -PropertyType DWORD -Force
This works great if I copy the script to the machine manually, and launch the script as a user. It looks at $home and figures out the correct directory based on whomever is logged in.
However, when it runs as Desktop Central, $home doesn't mean the same location. It comes back with this;
Expand-archive : The path 'C:\Windows\system32\config\systemprofile\Downloads\SWANDPDM_SP5.1.zip' either does not
exist or is not a valid file system path.
At C:\Program Files (x86)\DesktopCentral_Agent\Computer\startup\76507\SWandPDMdecomInstall.ps1:2 char:1
+ Expand-archive -path $home\Downloads\SWANDPDM_SP5.1.zip -DestinationP ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (C:\Windows\syst...NDPDM_SP5.1.zip:String) [Expand-Archive], InvalidOpe
rationException
+ FullyQualifiedErrorId : ArchiveCmdletPathNotFound,Expand-Archive
I tried using various env variables with no luck. It seems like because it's a "Desktop central" account that's running the script remotely, I can't get it to point to the correct folder in c:\users\NAMEOFLOGGEDINUSER\
So, it thinks $home = 'C:\Windows\system32\config\systemprofile\ instead of c:\users\NAMEOFLOGGEDINUSER\
Is there a way that I can get the username of the current logged on user, assign it to a variable, and then use that variable instead of $home? Keep in mind, it needs to find the logged in user while running the script as the Desktop Central service account. I've tried running the script as various domain admins\system accounts with no luck.
I thought about doing a whoami, writing to a text file, then omitting the domain portion of the output and assigning it to a variable, but there's got to be a better way.
Any help is greatly appreciated!
EDIT: Thought I was on to something, but it didn't work. I tried;
Expand-archive -path $env:HOMEPATH\Downloads\SWANDPDM_SP5.1.zip -DestinationPath C:\temp\swpdminstaller\extracted\ -Force
I see from the comments that you found a workaround. But to answer your original question, you can't get the logged in username from the usual Powershell techniques ($env:USERNAME, whoami, etc.) when you're running the script under a different security context.
But you can check who owns the Explorer.exe process:
$User = (Get-CimInstance Win32_Process -Filter "name = 'explorer.exe'" |
Invoke-CimMethod -MethodName GetOwner).User
The "Desktop central" user will probably not have Explorer running. However, if there are multiple users logged in via RDP sessions this will return an array.
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
We have a communication site where we need to disable the gear icon based on the permissions assigned to the users
I was referring to the below article
https://olafd.wordpress.com/2018/09/17/simple-solution-to-remove-the-gear-icon-in-sharepoint-online/?unapproved=1367&moderation-hash=83f4fa52244ea8c3fe83cc0179e617d7#comment-1367
Followed the steps mentioned in the article , However I come across the below error
Local File Not Found
Below is the Script I am trying to Execute
Write-Host "Upload RemoveGearIcon.js"
$f = Add-PnPFile -Path .\RemoveGearIcon.js -Folder "scripts"
$site = Get-PnPSite
$fileUrl = $site.Url + "/Scripts/RemoveGearIcon.js"
Write-Host "Add JavaScript Link"
$jsLink = Get-PnPJavaScriptLink -Name "RemoveGearIcon" -Scope Site
if ($jsLink -ne $null)
{
Remove-PnPJavaScriptLink -Identity "RemoveGearIcon" -Scope Site -Force
}
$link = Add-PnPJavaScriptLink -Name "RemoveGearIcon" -Url $fileUrl -Sequence 200 -Scope Site
I have not been able to figure out what could be going wrong and would appreciate if anyone here could help me with this or let me know any other alternative to get this done.
Thanks in Advance.
You need to make sure you have a library called "Scripts" on your site.
Please run the code again.
I am currently using the below PowerShell script to update an autologon value in the registry, it also checks that if the value isn't there that it is created.
Rather than opening up the script, changing the defaultpassword value in there and then running the script I'd like to be able to run the script in PowerShell and for it to prompt for the user to enter the value that is going to update.
I am new to parameters within PowerShell and can't say I'm 100% sure that is the solution.
Can anyone help? it's the 'passwordvalue' I'm looking to have inputed from a prompt and to be subsequently replaced in the script before the script runs. Let me know if I'm not being clear!
$RegKey = “HKLM:\SOFTWARE\MICROSOFT\WINDOWS NT\CURRENTVERSION\WINLOGON”
if (-Not(Test-Path “$RegKey”)) {
New-Item -Path “$($RegKey.TrimEnd($RegKey.Split(‘\’)[-1]))” -Name “$($RegKey.Split(‘\’)[-1])” -Force | Out-Null
}
Set-ItemProperty -Path “$RegKey” -Name “DefaultPassword” -Type String -Value “passwordvalue”
Just use the Read-Host cmdlet:
# ....
Set-ItemProperty -Path "$RegKey" -Name "DefaultPassword" -Type String -Value (Read-Host -Prompt 'Enter the password')
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