Files
Gl-Komp-IT-Sys/docs/powershell.md

114 lines
3.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Powershell
## Set-Password
> Command: Get-LocalUser -Name [Username] | Set-LocalUser -Password (ConvertTo-SecureString -AsPlainText [Password] -Force)
```ruby
Get-LocalUser -Name 'Administrator' | Set-LocalUser -Password (ConvertTo-SecureString -AsPlainText 'Passw0rd' -Force)
```
## Set-Hostname
> Command: Rename-Computer -NewName [Name der Maschine] -Restart -Force
```ruby
Rename-Computer -NewName 'DC01' -Restart -Force
```
## IP-Config
> Command: New-NetIPAddress -InterfaceIndex [Index des Interfaces] -AddressFamily [IPv4/IPv6] -IPAddress [IP-Adress] -PrefixLength [SNM / Prefix] -DefaultGateway [IP-Adresse des Default-Gateway]
```ruby
New-NetIPAddress -InterfaceIndex 3 -AddressFamily IPv4 -IPAddress '172.16.7.100' -PrefixLength '255.255.255.0' -DefaultGateway '172.16.7.254'
```
## DNS-Config
> Command: Set-DnsClientServerAddress -InterfaceIndex [Index des Interfaces] -ServerAddresses ("[IP-Adresse primärer DNS]","[IP-Adresse sekundärer DNS]")
```ruby
Set-DnsClientServerAddress -InterfaceIndex '3' -ServerAddresses ('172.16.7.11','172.16.7.12')
```
## Interface
<details>
<summary>Interface Name/Index auslesen</summary>
> Command: Get-NetIPInterface -AddressFamily [IPv6/IPv4]
```ruby
Get-NetIPInterface -AddressFamily 'IPv6'
```
</details>
## IPv6-abschalten
<details>
<summary>IPv6-abschalten</summary>
Schaltet IPv6 komplett ab!
> Command: Disable-NetAdapterBinding -Name [Name der Netzwerkkarte] -ComponentID ms_tcpip6
```ruby
Disable-NetAdapterBinding -Name 'eth0' -ComponentID ms_tcpip6
```
</details>
## IPv6-DHCP-abschalten
<details>
<summary>IPv6-DHCP-abschalten</summary>
Nur DHCPv6 abschalten
> Command: Set-NetIPInterface -InterfaceAlias [Name der Netzwerkkarte] -AddressFamily [IPv4/IPv6] -Dhcp Disabled
```ruby
Set-NetIPInterface -InterfaceAlias 'Inside' -AddressFamily 'IPv6' -Dhcp Disabled
```
> Command: Set-NetIPInterface -InterfaceIndex [Index der Netzwerkkarte] -AddressFamily [IPv4/IPv6] -Dhcp Disabled
```ruby
Set-NetIPInterface -InterfaceIndex '3' -AddressFamily 'IPv6' -Dhcp Disabled
```
</details>
## Set-Networkcard-to-private
Profil der Netzwerkkarte auf Privat umstellen (Firewall)
> Comman: Set-NetConnectionProfile -InterfaceIndex [Index der Netzwerkkarte] -NetworkCategory "Private"
```ruby
Set-NetConnectionProfile -InterfaceIndex '3' -NetworkCategory 'Private'
```
## Add-Route
> Command: New-NetRoute -DestinationPrefix [Subnet] -InterfaceIndex [Index der Netzwerkkarte] -NextHop [IP-Adress] -RouteMetric [Metric]
```ruby
New-NetRoute -DestinationPrefix '172.16.0.0/20' -InterfaceIndex '7' -NextHop '172.16.X.254' -RouteMetric '1'
```
## Remote-Access
Read TrustedHosts
```ps
Get-Item WSMan:localhost\client\TrustedHosts
```
Set TrustedHost
> Command: Set-Item WSMan:localhost\client\TrustedHosts Value '[IP bzw. hostname]'
> Command: Set-Item WSMan:localhost\client\TrustedHosts Value '[IP bzw. hostname],[IP bzw. hostname]'
```ruby
Set-Item WSMan:localhost\client\TrustedHosts Value '172.16.7.254'
```
Activate Remote-PS
```ruby
Enable-PsRemoting
```
## Remote PS Execute
Remote befehle oder scirptblöcke ausführen
> Command: Invoke-Command ComputerName [IP bzw. FQDN] Credential [User] Command {[Befehl]}
> Command: Invoke-Command ComputerName [IP bzw. FQDN] Credential [User] ScriptBlock {[Befehle]}
```ruby
Invoke-Command ComputerName [IP bzw. FQDN] Credential [User] Command {[Befehl]}
```
```ruby
Invoke-Command ComputerName [IP bzw. FQDN] Credential [User] ScriptBlock {[Befehle]}
```
> Command:
```ruby
```