PowerShell open Internet Explorer and connect to Website with Credentials - powershell

Is it possible to create a PowerShell Script that opens Internet Explorer, and connect to an internal IIS Website with credentials?
First part is easy:
$ie = New-Object -Com InternetExplorer.Application
$ie.visible = $true
$ie.navigate("http://mysite")
Now I have no idea how to solve the second part. IE starts and security popup comes up.
Anyone an idea how to handover the credentials? Thanks in advance.
PS: It's an internal IIS Server. I can choose from Basic or Windows Authentication.

If integrated Auth is helpful, how about using Start-Process with the -Credential parameter.
Start-Process -FilePath "C:\Program Files (x86)\Internet Explorer\iexplore.exe" -ArgumentList "http://mysite" -Credential $YourCreds
Or you wrap that to get the correct folder if this will be running on different computers.
if ($arch = $env:PROCESSOR_ARCHITECTURE -eq 'AMD64') {
Start-Process -FilePath "C:\Program Files (x86)\Internet Explorer\iexplore.exe" -ArgumentList "http://mysite" -Credential $YourCreds
}
else {
Start-Process -FilePath "C:\Program Files\Internet Explorer\iexplore.exe" -ArgumentList "http://mysite" -Credential $YourCreds
}

Related

Install MSI on remote computer using Powershell

I am trying to write a Powershell script which will deploy software on a collection of WS2016 servers. I am a local administrator on all these servers. Here's what I have so far:
$Cred = Get-Credential
$Computer = 'myserver.contoso.com'
$SplunkMSI = '\\mylocalbox\C$\Splunk.msi'
$InstallDir = 'C:\Apps\Splunk\'
$sb = {
param($installer, $dir)
Start-Process -FilePath 'c:\windows\system32\msiexec.exe' -ArgumentList "$installer INSTALLDIR=$dir AGREETOLICENSE=Yes /qn /norestart /L*v C:\temp\splunkInstall.log" -Wait -NoNewWindow
}
Write-Host "Deploying Splunk to host $Computer"
Invoke-Command -Computer $Computer -Credential $Cred -ScriptBlock $sb -ArgumentList $SplunkMSI, $InstallDir -ErrorAction Stop
When I run this script, I get prompted for credentials, and then I see the output of the Write-Host, but then... nothing. I have to manually terminate the script.
I logged onto the remote host, but see no evidence that the MSI was executed or failed to execute.
Anyone see a smoking gun?
ya, it looks like it's looking for $installer and $dir in the script block but they're not specified

Powershell Start-Process -NoNewWindow not working with -Credentials

I am looking to run an exe from powershell using a credential. I want the output to be in the same window. This is how my powershell looks.
Start-Process documentation: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/start-process?view=powershell-6
$username = 'user'
$password = 'password'
$credentials = New-Object System.Management.Automation.PSCredential -ArgumentList #($username,(ConvertTo-SecureString -String $password -AsPlainText -Force))
$pathNew = "c:\pathtomyexe\text.exe"
Start-Process $pathNew -NoNewWindow -Credential ($credentials) -PassThru -Wait
With -Credential ($credentials) a new window is launched.
When I run Start-Process without -Credential, I get result in the same window as expected.
Start-Process $pathNew -NoNewWindow -PassThru -Wait
What am I doing wrong? Any pointers?
Short answer, you aren't doing anything wrong. You just won't be able to do this.
When you run Start-Process -NoNewWindow without -Credential you say: with the current already authenticated credentials, run the executable, and return the results within the same console window.
When you run Start-Process with -Credential the first question is: how do you verify that the Credentials are valid? You can't just look at the username and assume that you can re-use the existing session (e.g. the password might be wrong). To validate the credentials, Start-Process launches a new process as the username/password provided in the Credential object. It performs an authentication check and get a new authentication ticket.
Since it's a new process, running under a completely new context, with new authentication ticket, it ignores the -NoNewWindow flag as there is no way for the current console to redirect the output of the new process, and launches it as a new window.

powershell execute start-process on remote machine

IDE: PowerShell ISE
I have a script which installs the chrome to a remote machine
#Script : Test01.ps1
Start-Process D:\Chrome\Chrome.exe -wait -verb runas
write-host "Chrome is installed"
and I am executing the above script using :
Invoke-Command -ComputerName MySystem18 -FilePath D:\Test01.ps1 -ArgumentList Process
The above script is working on local system (MySystem03) and remote machine (MySystem18).
But when I am executing this in MySystem18 it is not showing up the acknowledgement or cursor after the installation of chrome, even after successful installation of chrome on MySystem18.
Can you tell me how to fix it.
D:\Chrome\Chrome.exe is a path on your remote computer ? If not, try to share a dir with Chrome.exe named yourdirshared on your mysystem03 and replace by \\mysystem03\yourdirshared\Chrome.exe into your ps1
if always doesnt work, you can try to remove -wait my be...
if always doesnt work, are you try to specify credentil parameter?
$Username = 'username'
$Password = 'yourpassword
$pass = ConvertTo-SecureString -AsPlainText $Password -Force
$Cred = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$pass
Invoke-Command -ComputerName "MySystem18" -Credential $Cred -ScriptBlock {Start-Process D:\Chrome\Chrome.exe -wait -verb runas; write-host "Chrome is installed" }

run another program with credentials

what I'm trying to do is add a user to the local admin group then launch a program with those credentials. I have the first part working:
$env:COMPUTERNAME
$srvgroup = [ADSI]("WinNT://"+$env:COMPUTERNAME+"/Administrators, Group")
$srvgroup.name
$srvgroup.add("WinNT://userID,user")
$srvgroup.Invoke("Members") | foreach {$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}
The second part is what I can't seem to get working correctly.
Start-Process runas.exe -Credential DOMAIN\user -ArgumentList '-noprofile -command & "C:\Program Files (x86)\Misc\SecureClient" -verb runas}'
I don't get an error message but the program does not start. I should get a popup window for the application but nothing happens when I try it this way.
Any ideas?
DOMAIN\user is not a full credential. You need to do something like this:
$passwd = ConvertTo-SecureString "opensesame" -Force -AsPlainText
$cred = new-object pscredential 'Domain\user',$passwd
Start-Process -Credential $cred ...
I ended up doing it like, don't really like it but it works:
start-process "cmd.exe" "/c D:\Scripts\client_connect.cmd"
that .cmd file is:
C:\Windows\System32\runas.exe /savecred /user:domain\username"C:\Program Files (x86)\xxx\xxx\sclient.cmd"

Running powershell via Start-Proces with elevated credentials hangs for several minutes on Win7 64bit when on network

I have a number of scripts that require sections of them to run with elevated privileges.
If I do the following:
pw= convertto-securestring "PASSWORD" -asplaintext –force
$pp = new-object -typename System.Management.Automation.PSCredential -argumentlist "DOMAIN\user",$pw
$script = "c:\pathtoscript.ps1"
Start-Process powershell -Credential $pp -ArgumentList '-noprofile -command &{Start-Process $script -verb runas}'
It works fine when there is no network cable connected. However, when I try with the network connected it hangs for 2-3 minutes, although it does finally run the script.
To make it even weirder, it works fine opening any process other than Powershell, and it works fine opening powershell if there are no arguments specified.
Well, this is not a PowerShell issue. It is to do with home directory access.
Can you try this registry change?
Add a REG_DWORD value named StartRunNoHOMEPATH in the following registry key:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer