PowerShell, force Internet Explorer to perform its first-launch configuration? - powershell

I often hit the dreaded Internet Explorer's first-launch configuration is not complete. Specify the UseBasicParsing parameter and try again error when using Invoke-WebRequest.
Various pages point out this issue and the use of the UseBasicParsing switch, but it is an annoyance to have to put that into every command.
Is there a way that I can declare, at the start of a script, some commands to force Internet Explorer to silently perform its first-launch configuration and accept all defaults so that the UseBasicParsing switch is no longer required?

This answer on the page you provided actually suggests setting the registry value with PowerShell that will disable the first run wizard for Internet Explorer and allow you to use Invoke-WebRequest without -UseBasicParsing parameter.
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Internet Explorer\Main" -Name "DisableFirstRunCustomize" -Value 2

Related

Running powershell without useriteraction

start "odopen://sync/?siteId=$siteid17&webId=$webid17&listId=$listid17&userEmail=$upn&webUrl=$URL17&webtitle=$webtitle17&listtitle=$listtitle17"
How is it possible to run the following command inside Powershell without an appearing popup window or any userinteraction? I've tried adding /ArgumentList "/S", "/Background". Also tried with -WindowStyle Hidden at the end. Appreciate some help :)
Your command as-is basically says "Start the program that opens odopen:// (OneDrive) links" and can't really be given any silent style instructions. The proper way to configure this kind of thing is through OneDrive Group Policies, but we can cheat and set registry keys.
The link above goes into detail about how to configure group policy, but also tells us that the specific group policy setting to "Configure team site libraries to sync automatically" sets this registry key:
[HKCU\Software\Policies\Microsoft\OneDrive\TenantAutoMount]"LibraryName"="LibraryID"
And that your LibraryID is in this format, which looks familiar:
tenantId=xxx&siteId=xxx&webId=xxx&listId=xxx&webUrl=httpsxxx&version=1
So to put it in a script, I would use something like this, adapted from Nicola Suter's blog post here:
$tenantAutoMountRegKey = "HKLM:\SOFTWARE\Policies\Microsoft\OneDrive\TenantAutoMount"
$autoMountTeamSitesList= #{
#Enter your SharePoint libraries to configure here as key/value pairs
MySharePoint="odopen://sync/?siteId=$siteid17&webId=$webid17&listId=$listid17&userEmail=$upn&webUrl=$URL17&webtitle=$webtitle17&listtitle=$listtitle17"
}
# Check if the key exists and create if missing:
if (-not (Test-Path $tenantAutoMountRegKey)){ New-Item -Path $tenantAutoMountRegKey -Force }
# Add the sites for automatic mounting
$autoMountTeamSitesList | Set-ItemProperty -Path $tenantAutoMountRegKey -Name $_.Key -Value $_.Value
This generally takes effect the next time a user signs into OneDrive, though Microsoft warns it may take up to 8 hours to start syncing (Keeps hundreds of users from syncing the same library at the same time)
TL;DR: You cannot.
Using odopen will always show sign-in window (as stated here: https://learn.microsoft.com/en-us/onedrive/deploy-on-windows#help-users-sign-in), what you can do is only populate it with data, which is what you are already doing.
If you want to do it silently, there is documentation about it: https://learn.microsoft.com/en-us/onedrive/use-silent-account-configuration

How to pin Internet Explorer to taskbar with PowerShell

I am setting a script to pin internet explorer to task-bar for all users using Power Shell. the code i have run only is successfully for pinning notepad but i want it to work for internet explorer. Any one who can help me on this?
$sa = new-object -com shell.application
$pn = $sa.namespace($env:windir).parsename('iexplorer.exe')
$pn.invokeverb('taskbarpin')
I have tried putting parsename('notepad.exe') and it ran,But i want to put internet explorer like this parsename('iexplorer.exe').
When i run the code the console says powershell: You cannot call a method on a null-valued expression.
if you check what $pn.items() returns, you can see there is no internet explorer.
You need to use the installation path of the internet explorer as an namespace.
Try it like that:
$sa.namespace("C:\Program Files\internet explorer").parsename('iexplore.exe')
Note:
Transfered comment to answer

Powershell Handling cookie popup without using invoke-webrequest

I am attempting to get a script working that does not use invoke-webrequest. The problem I am having is that when I run the script a popup prompt occurs, the popup consists of the following message;
"Windows Security Warning
To allow this website to provide information personalized for you, will you allow it to put a small file (called a cookie) on your computer?"
with yes no response from user
The code I am executing is the following:
$ParsedHTML = New-Object -com "HTMLFILE"
$webresponse = New-Object System.Net.WebClient
$webresponse.Headers.Add("Cookie", $CookieContainer.GetCookieHeader($url))
$result = $webresponse.DownloadString($url)
$ParsedHTML.IHTMLDocument2_write($webresponse)
$ParsedHTML.body.innerText
The main problem with this code is that the $url I am using part of the weblink checks to see if cookies are enabled and this code causes a returned value of disabled.
My question, is there a way to handle the cookie request without changing the output response from the test url site.
Note: This script will be automating a process over hundreds of remote computers and thus having an unhandled popup will just prevent the script from running.
I found the answer in another SO question Using Invoke-Webrequest in PowerShell 3.0 spawns a Windows Security Warning
add the parameter -UseBasicParsing
Technet https://technet.microsoft.com/en-us/library/hh849901.aspx notes that the parameter stops the DOM processing. and has the caveat "This parameter is required when Internet Explorer is not installed on the computers, such as on a Server Core installation of a Windows Server operating system."
So, you mileage may vary.

The Win32 internal error "The handle is invalid" 0x6 occurred while getting the console mode

I currently have some problems with the azure commandline in a Web App.
I get following error:
[10/28/2015 20:22:33 > 37539e: ERR ] New-Item : The Win32 internal error "The handle is invalid" 0x6 occurred while
[10/28/2015 20:22:33 > 37539e: ERR ] getting the console mode. Contact Microsoft Customer Support Services.
This occurred on New-Item and Remove-Item. It happens in the Kudo Powershell console and using Powershell-Scripts ina WebJob.
Instead of New-Item file I have successfully used echo 3 >> file. This worked without problems. The only thing I found was that there is a problem using Invoke-WebRequst and that it will be fixed using
$ProgressPreference="SilentlyContinue"
Unfortunately this didn't helped.
Did someone experienced something similar?
Thanks in advance.
Some cmdlets may attempt to read the console mode of the standard input or standard output streams if it is attached to the console. This can be avoided by setting them explicitly to null.
# Prevent the progress meter from trying to access the console mode
$ProgressPreference = "SilentlyContinue"
# Set the input and output streams to $null
$null | Invoke-WebRequest -UseBasicParsing http://www.example.com/ > $null
For me, setting $ProgressPreference="SilentlyContinue" does solve the issue.
(Using the PowerShell Console of the Kudu site of an Azure App Service.)
$null | (…) > $null also prevents the error, but that also suppresses the return value, which I don't want.
Background: Apparently Invoke-WebRequest tries to display a progress bar, which Kudu's PowerShell does not support. (source)
The error seems to be related to the protection of our proprietary sandbox for Web Apps. However, one possibility is to use Windows Containers on App Service.
Here you can follow the quickstart to run a Windows Container in App Service:
https://learn.microsoft.com/en-us/azure/app-service/app-service-web-get-started-windows-container

Boxstarter or PowerShell command to change "Opens With" properties

I'm trying to develop my own Boxstarter script for spinning up new machines. I just realized that I'd really like to add a line that will change default applications to open certain file types. For example, I want to open .txt files with Notepad++. I know how to do this by right-click the file and checking it's properties, but is there a line I can add to my Boxstarter script that will do it? Or, since Boxstarter is basically a special set of PowerShell commands, is there a PowerShell command I can invoke directly to change the opens with property? I did some searching, and most of the results were about how to get PowerShell to open something, not change the opens with property. The rest were all about how to open PowerShell.
Another similar, but not quite the same, way to go about this is to change the file association you want to associate with a particular applicaition. Chocolatey includes some helper commands to do this and is therefore available to your Boxstarter package. Here is an excerpt from one of my Boxstarter packages:
Install-ChocolateyFileAssociation ".txt" "$env:programfiles\Sublime Text 2\sublime_text.exe"
Install-ChocolateyFileAssociation ".dll" "$($Boxstarter.programFiles86)\jetbrains\dotpeek\v1.1\Bin\dotpeek32.exe"
So now double clicking on any text file opens sublime or any dll opens dotpeek.
But I agree. Its still helpful to be able to add to the "Open With..." list.
Thanks to #Raf for pointing me in the right direction. Here's the code to change the OpensWith property of .txt files:
$principal = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
$key = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.txt\UserChoice",[Microsoft.Win32.RegistryKeyPermissionCheck]::ReadWriteSubTree,[System.Security.AccessControl.RegistryRights]::ChangePermissions)
$acl = $key.GetAccessControl()
$right = "SetValue"
$denyrule = New-Object System.Security.AccessControl.RegistryAccessRule($principal,$right,"DENY")
$ret = $acl.RemoveAccessRule($denyrule)
$ret = $key.SetAccessControl($acl)
Set-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.txt\UserChoice -Name ProgId -Value Applications\notepad++.exe
Slightly modified from an answer in the TechNet forums.
I haven't figured out if there's a boxstarter shortcut for this, but changing the ACL rules was the key. Without it, you don't have the proper access to change this particular registry item. Even when I tried running Powershell as Admin and made sure I had all the right permissions on the UserChoice key (both the administrator account and my user account had Full Control), I kept getting an error that the Requested registry access is not allowed.