PowerShell: Difference between revisions

From Chorke Wiki
Jump to navigation Jump to search
 
(23 intermediate revisions by the same user not shown)
Line 10: Line 10:
Invoke-Command  -ComputerName 10.19.83.10 -ScriptBlock { Get-ChildItem C:\ } -Credential academia
Invoke-Command  -ComputerName 10.19.83.10 -ScriptBlock { Get-ChildItem C:\ } -Credential academia
Enter-PSSession -ComputerName 10.19.83.10 -Credential academia
Enter-PSSession -ComputerName 10.19.83.10 -Credential academia
</source>
==OpenSSH==
<source lang="powershell">
Get-WindowsCapability -Online | ? Name -like 'OpenSSH*'
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
</source>
<source lang="powershell">
dism /Online /Get-Capabilities | findstr OpenSSH
dism /Online /Add-Capability /CapabilityName:OpenSSH.Client~~~~0.0.1.0
dism /Online /Add-Capability /CapabilityName:OpenSSH.Server~~~~0.0.1.0
</source>
<source lang="powershell">
Start-Service sshd
Set-Service -Name sshd -StartupType 'Automatic'
Get-NetFirewallRule -Name *ssh*
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
</source>
<source lang="bat">
notepad++ %PROGRAMDATA%\ssh\sshd_config
</source>
<source lang="ini" highlight="1" start="34" line>
PubkeyAuthentication yes
# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile .ssh/authorized_keys
</source>
<source lang="ini" highlight="2" start="50" line>
# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication yes
#PermitEmptyPasswords no
</source>
<source lang="ini" highlight="2,3" start="75" line>
# override default of no subsystems
#Subsystem sftp sftp-server.exe
Subsystem powershell c:/progra~1/powershell/7/pwsh.exe -sshs -NoLogo -NoProfile
</source>
<source lang="powershell">
pwsh
~/powershell/pwsh
Enter-PSSession -HostName 10.19.83.10 -UserName academia
</source>
==PowerShell Core==
<source lang="powershell">
cd ~\Downloads
msiexec.exe /package PowerShell-7.1.0-win-x64.msi /quiet ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 ENABLE_PSREMOTING=1 REGISTER_MANIFEST=1
Install-Module -Name Microsoft.PowerShell.RemotingTools
</source>
==Web PowerShell==
<source lang="bat">
@rem command only
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "[System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://cdn.chorke.org/exec/cli/ps1/hello.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\academia\bin"
</source>
<source lang="powershell">
# power shell only
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://cdn.chorke.org/exec/cli/ps1/hello.ps1'))
</source>
</source>


Line 54: Line 123:


| valign="top" |
| valign="top" |
* [https://365adviser.com/powershell/install-use-openssh-windows-powershell-core-remoting-via-ssh/  Install & Use OpenSSH on Windows for PowerShell Core Remoting]
* [https://abouconde.com/2020/07/06/winrm-firewall-exception-will-not-work-since-one-of-the-network-connection-types-on-this-machine-is-set-to-public-change-the-network-connection-type-to-either-domain-or-private-and-try-again/ Change the network connection type to either Domain or Private]
* [https://abouconde.com/2020/07/06/winrm-firewall-exception-will-not-work-since-one-of-the-network-connection-types-on-this-machine-is-set-to-public-change-the-network-connection-type-to-either-domain-or-private-and-try-again/ Change the network connection type to either Domain or Private]
* [https://www.hurryupandwait.io/blog/fixing-winrm-firewall-exception-rule-not-working-when-internet-connection-type-is-set-to-public WinRM <code>Firewall Exception Hacks</code> for Public Network]
* [https://www.hurryupandwait.io/blog/fixing-winrm-firewall-exception-rule-not-working-when-internet-connection-type-is-set-to-public WinRM <code>Firewall Exception Hacks</code> for Public Network]
* [https://www.hanselman.com/blog/installing-powershell-core-on-a-raspberry-pi-powered-by-net-core Installing PowerShell Core on a Raspberry Pi]
* [https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse Installing OpenSSH with PowerShell]
* [https://geektechstuff.com/2019/09/25/installing-powershell-core-on-raspbian-rasbperry-pi/ Installing PowerShell Core on Pi OS]
* [https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-windows?view=powershell-7.1 Installing PowerShell on Windows]
* [https://github.com/PowerShell/PowerShell/releases GitHub Release of PowerShell]
* [https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-7.1#installation---raspbian Raspberry Pi Installation]
* [https://dotnet.microsoft.com/download/dotnet-core Download Dotnet Core]
|}
----
{|
| valign="top" |
* [https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/write-host?view=powershell-7.1 <code>Microsoft.PowerShell.Utility Write-Host</code>]
* [https://chocolatey.org/install Install Chocolatey using web hosted PowerShell]
* [https://devblogs.microsoft.com/scripting/understanding-the-six-powershell-profiles/ Understanding the Six PowerShell Profiles]
* [https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-5.0 Host and Deploy ASP.NET Core 5.0 on IIS]
* [https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-3.1 Host and Deploy ASP.NET Core 3.1 on IIS]
* [https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-2.1 Host and Deploy ASP.NET Core 2.1 on IIS]
* [https://github.com/minio/minio-service/tree/master/windows Running MinIO as a service on Windows]
* [https://stackoverflow.com/questions/43902878/ Run PowerShell script from URL]
* [https://superuser.com/questions/344927/ PowerShell Equivalent of cURL]
* [https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles?view=powershell-7.2 About PowerShell Profiles]
| valign="top" |
|}
|}

Latest revision as of 00:45, 3 August 2022

Get-Service WinRM
Restart-Service WinRM
Enable-PSRemoting -Force
Set-Item WSMan:\localhost\Client\TrustedHosts *
WinRM s winrm/config/client '@{TrustedHosts="10.19.83.10,10.19.83.14"}'

WinRM quickconfig
Test-WsMan 10.19.83.10
Invoke-Command  -ComputerName 10.19.83.10 -ScriptBlock { Get-ChildItem C:\ } -Credential academia
Enter-PSSession -ComputerName 10.19.83.10 -Credential academia

OpenSSH

Get-WindowsCapability -Online | ? Name -like 'OpenSSH*'
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
dism /Online /Get-Capabilities | findstr OpenSSH
dism /Online /Add-Capability /CapabilityName:OpenSSH.Client~~~~0.0.1.0
dism /Online /Add-Capability /CapabilityName:OpenSSH.Server~~~~0.0.1.0
Start-Service sshd
Set-Service -Name sshd -StartupType 'Automatic'

Get-NetFirewallRule -Name *ssh*
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
notepad++ %PROGRAMDATA%\ssh\sshd_config
PubkeyAuthentication yes

# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile	.ssh/authorized_keys
# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication yes
#PermitEmptyPasswords no
# override default of no subsystems
#Subsystem	sftp	sftp-server.exe
Subsystem powershell c:/progra~1/powershell/7/pwsh.exe -sshs -NoLogo -NoProfile
pwsh
~/powershell/pwsh 
Enter-PSSession -HostName 10.19.83.10 -UserName academia

PowerShell Core

cd ~\Downloads
msiexec.exe /package PowerShell-7.1.0-win-x64.msi /quiet ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 ENABLE_PSREMOTING=1 REGISTER_MANIFEST=1
Install-Module -Name Microsoft.PowerShell.RemotingTools

Web PowerShell

@rem command only
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "[System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://cdn.chorke.org/exec/cli/ps1/hello.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\academia\bin"
# power shell only
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://cdn.chorke.org/exec/cli/ps1/hello.ps1'))

Knowledge

Get-Service WinRM
Restart-Service WinRM
Enable-PSRemoting -Force
Get-Item WSMan:\localhost\Client\TrustedHosts
Set-Item WSMan:\localhost\Client\TrustedHosts *
Set-Item WSMan:\localhost\Client\TrustedHosts -Force -Value 10.19.83.10

$s = New-PSSession -ComputerName "10.19.83.10" -Credential(Get-Credential)
Invoke-Command -Session $s -ScriptBlock { Get-ChildItem C:\ }
Invoke-Command -Session $s -ScriptBlock { Get-Service }

Get-NetConnectionProfile
Set-NetConnectionProfile -InterfaceIndex 10 -NetworkCategory Private

Set-WSManQuickConfig
Enable-PSRemoting -SkipNetworkProfileCheck
Get-NetConnectionProfile | Set-NetConnectionProfile -NetworkCategory Private
brew cask install powershell
brew upgrade powershell --cask
brew tap homebrew/cask-versions

References