Enable tunneling of connections web logic server - weblogic12c

I have web logic server installed and I want to enable tunneling of connections on it. I cannot use http://docs.oracle.com/cd/E13222_01/wls/docs81/ConsoleHelp/servers.html#Configuring_HTTP_Protocol because I have just access from the command line.
Please, there a way to do that from command line?
Thanks,

After setting your environment (. wlserver/server/bin/setWLSEnv.sh on linux) the following should do the trick so long as you supply the proper values for $url, $username and $password.
java weblogic.Admin -url $url -username $username -password $password SET -type Server -property TunnelingEnabled true

Related

Selenium (Powershell) Run as a different user

I want to start Selenium (Google Chrome - WebDriver) as a different user and I am pretty much lost as I don't know where to add $mycreds. This is quite easy to achieve if I want to start a normal Chrome session, however, I am stuck when it comes to achieving this using Selenium. Any advice ?
$username = "domain\name"
$password = ConvertTo-SecureString "password" -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential -ArgumentList $username, $password
$Driver = Start-SeChrome
Enter-SeUrl -Url 'https://www.google.com/' -Driver $Driver
If I try to pass it along using -Arguments , it will still use my account to open the browser without returning any error.
$Driver = Start-SeChrome -Arguments $mycreds
The easy way to do this is by starting Powershell as-another-user instead. Make sure you have the module set up for that user as well as any other environment stuff you might need.
The selenium-powershell module itself does not support starting the selenium drivers as a different user from the current one.
You may also want to make sure you're using an updated version of the module as well, since (in pre-release):
Start-SeChrome and other have been removed in favor of Start-SeDriver -Browser Chrome (#100)

Connecting Exchange Online Fails when passing proxy and running in System PowerShell - TokenProvider Returns Object Reference Error

I was connecting Exchange Online using a PowerShell window that is opened with system access. I used PSExec on an elevated Command Prompt to open the System access PowerShell. Below is the command.
PSExec -i -s PowerShell
On the PowerShell, I imported the latest Exchange Online Management PowerShell module version 2.0.3. I use the app-based authentication described here: https://learn.microsoft.com/en-us/powershell/exchange/app-only-auth-powershell-v2?view=exchange-ps#setup-app-only-authentication.
There is one more website that shows how to connect with app-based authentication: https://o365reports.com/2020/07/04/modern-auth-and-unattended-scripts-in-exchange-online-powershell-v2.
Below are the commands used to connect to Exchange Online.
Import-Module .\ExchangeOnlineManagement
$sessopt = New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck -ProxyAccessType IEConfig
$certkey = ConvertTo-SecureString "<EnterCertificateKeyHere>" -AsPlainText -Force
Connect-ExchangeOnline -CertificateFilePath "pfx Certificate Path" -AppId <EnterAppIdHere> -Organization "domain.onmicrosoft.com" -CertificatePassword $certkey -PSSessionOption $sessopt -verbose
When running the above, it returns Object Reference error. I got excited and went on to find what the error is by decompiling the DLL files and found that inside the 'ExoPowershellGalleryModule.dll -> NewExoPSSession.cs' of the Exchange module, the 'GetAccessToken' function which is called around line:308 causes this error. Any idea what makes the Object reference not set to an instance of an object. System.Management.Automation.RemoteException: Object reference not set to an instance of an object. error. Was the proxy not taken from IE?
I've set the proxy settings in IE using the below Powershell command-lets in system PowerShell.
Set-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -name ProxyServer -Value "ProxyServerAddress"
Set-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -name ProxyEnable -Value 1
Any help to resolve this is appreciated.
If your using
PSExec -i -s PowerShell
Then the proxy information your entering for the user will have no effect because the local system account will have its own profile information. Also if the proxy needs authentication you also won't be presenting any Network credentials.
If you really want to run under the system account you could try using netsh to configure the proxy https://learn.microsoft.com/en-us/windows/security/threat-protection/microsoft-defender-atp/configure-proxy-internet but if you proxy need authentication this won't work.

PowerShell - File transfer from windows to unix

I am working on UIpath automation for which I need some files to be transferred back and forth between Windows and Unix machines (only through PowerShell). Kindly provide your inputs as I'm a newbie.
I am using plink in my PowerShell script to connect to a Unix server. Though it works fine, is there any other better way to connect to a Unix server (HP UX) from Windows (through a PowerShell script).
Struggling to find a good module and sample scripts to do a secure copy between the Unix and Windows servers. I came across Posh SSH /WinSCP, sftp etc. but I'm not able to implement any as I do not find the right sample scripts. Also Install-Module does not work (not recognized).
Your help on this would be much appreciated.
Thanks in advance!
If you want to use SFTP I am using the code below to upload some files automatically to an ftp site:
First of all you have to download the winscp SFTP powershell libraries.
https://winscp.net/eng/download.php
then extract the contents at the same location the script is located.
Then in your script you must add:
# Load WinSCP .NET assembly
# Give the path the dll file is located so powershell can call it.
Add-Type -Path "C:\Path where the dll file is located\WinSCPnet.dll"
# Setup session options
# Add all the properties the session needs to be established such as username password hostname and fingerprint.
# The username and password must be in plaintext.
$sessionOptions = New-Object WinSCP.SessionOptions -Property #{
Protocol = [WinSCP.Protocol]::Sftp
HostName = "HostName"
UserName = "UserName"
Password = "Password"
SshHostKeyFingerprint = "SSH fingerprint"
Then after the session with those credentials is up you must put your next step of copying the files.
# Open a session to the Host
# Try to connect to the Host with the credentials and information provided previously.
# Upload the file from a specific path to the path on the host.
# And then close the session and clean up the session trace data.
# $session.Dispose() -> If session was opened, closes it, terminates underlying WinSCP process, deletes XML log file and disposes object.
$session = New-Object WinSCP.Session
Try
{
# Connect to the SFTP site
$session.Open($sessionOptions)
# Upload the files from local disk to the destination
$session.PutFiles("Path of the file you want to upload", "/import/").Check()
}
Finally
{
# Disconnect, clean up
$session.Dispose()
}
Probably there is an easier way with Power Shell 6 that can do more with the Unix/Linux operating systems but at this point of answering I haven't used it.
Once you get Posh-SSH installed, something like this will probably get you down the road. There are ways to keep the password in plain text out of your script.
$SecurePassword = ConvertTo-SecureString -AsPlainText 'thepassword' -Force
$Credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'me',$SecurePassword
$Session = New-SFTPSession -ComputerName 'zenith' -Credential $Credentials -ConnectionTimeout 30
$r = Set-SFTPFile -Session $Session. -LocalFile 'C:\Users\me\t.txt' -RemotePath '/home/me' -Overwrite
Remove-SFTPSession -SFTPSession $session | Out-Null

Powershell remote access to nanoserver on docker

I have created a W10 VM (guest) running docker, pulled microsoft/nanoserver image and hosted a container of the image.
(tutorial here: https://msdn.microsoft.com/en-us/virtualization/windowscontainers/quick_start/quick_start_windows_10)
Everything runs great, even host can ping the container running under guest W10. But what i cannot do, is to connect a remote powershell to container.
Enter-PSSession -ComputerName "<container ip>" -Credential ~\Administrator
This pops up a dialog asking for user and password. I cannot leave it blank or etc - the result is access denied. Any ideas how to connect or set a password for nanoserver container ?
I've been struggling with this for a few days now. However, think my problem is slightly different though, as I'm trying to do an Enter-PSSession to a windows docker container, but from another machine, not the container host.
In this tutorial (http://dinventive.com/blog/2016/01/30/windows-server-core-hello-container/), the guy makes a nested container PSSession inside a host PSSession.
He uses this command, which is only available in the latest versions of Powershell. (not in v3)
Enter-PSSession -ContainerId "<container ID>"
Get the ID by doing :
Get-Container | fl
You also have to check your Powershell version and make an upgrade if needed.
To check PS version :
$PSVersionTable
And to download Powershell latest version : https://www.microsoft.com/en-us/download/details.aspx?id=50395
When connecting to a PS-Session using a IP address it adds some requirements, You must either have the remote device configured to use ssl or have the IP address listed in your trusted hosts.
The solution is to either try use the host name for the device, I have had great success with this. Or play with the trusted hosts list. In my experience it works consistently if you add trusted list entries on your machine and the remote machine as well. You can also specify:
Set-Item WSMan:\localhost\Client\TrustedHosts -Value "*"
This will basically set all machines to be in the trusted hosts list, It has its cons like all machines being trusted but in certain restricted networks its acceptable. Doing this on the host and client machine seems to yield best results.
When specifying -Credentials it expects a credential object, You can craft one before the cmdlet to avoid entering it every time like so:
$secpass = convertto-securestring "Password Here" -asplaintext -force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist "Username Here", $secpass
Enter-PSSession -ComputerName "<container ip>" -Credential $cred
Coding credentials like this in a script is bad practice, You should look in to storing credentials in scripts properly, there are plenty of good resources on it.

Trust relationship auto fix script

i am trying to come up with a script to automate the fix for the common issue in domain environment "the trust relationship error " for my help-desk employee , where they can just run the script with required variable
options : using power-shell or PsExec and should accept user input for naive user .
looking at powershell a simple line may fix the issue after google research : " Test-COmputerSecureChannel -Repair " which does not require reboot as well
challenges in powershell per my simple knowledge ( remote command execution should be enabled in remote machine which is not an option
> PsExec not available by default windows 7 / citrix employee
computer name : SAWD456335355 ( should be variable - user input )
local admin : Administrator
local password: variable differ from computer to computer ( should be user input as well accept special character )
=================================
Privilege admin level 1 account for pop up
while trying to change the local computer using team viewer a pop up will ask for domain credentials for instance :
user name would be sth like : admingroup1
password for privlege admin : password#123 < for example
There are three ways you could fix this.
What you are actually asking for, repair the secure channel. You will most likely need a local admin account (local because the trust relationship is broken) and a combination of Psexec and PowerShell remoting.
<# Get Help desk operator input#>
$Computer = Read-Host "Enter Computer name"
$AdminAccount = Read-Host "Enter local Admin Account"
$SecurePassword = Read-Host "Enter local Admin Password" -AsSecureString
<# Create Plain text password object and Credential Object#>
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecurePassword)
$UnsecurePassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $AdminAccount, $SecurePassword
<#Enable PS Remoting#>
Psexec.exe \$Computer -u $AdminAccount -p $UnsecurePassword -h -d powershell.exe "enable-psremoting -force"
<# Repair secure Channel#>
Invoke-Command -ComputerName $Computer -Credential $Credential -ScriptBlock {
Test-ComputerSecureChannel -Repair
}
Set the domain to NOT reset domain computer accounts. This is probably not recommended in most environments.
In my environment I found the best solution was to prevent automatic system restore (probably after a power outage or similar) that is older than the computer password as discussed here:
https://support.microsoft.com/en-us/kb/295049
My solution was to run a scheduled task to delete system restore points that are older than the current computer password.
Get-ComputerRestorePoint |`
Where {$_.ConvertToDateTime($_.CreationTime) -lt $PasswordLastSet} | `
Delete-ComputerRestorePoints
If no system restore points are left the script creates a new one.
A detailed write up can be found here:
http://blog.buktenica.com/issues-with-domain-membership-after-system-restore/