# Windows

Anything related to Windows and Powershell work I've come across

# Domain Join

Using service account and password to join Computer to the domain.

You might want to check if the computer is already join to a domain using:

# CHECK IF DOMAIN HAS JOIN
Get-WmiObject -Class Win32_ComputerSystem
$current_hostname = $env:computername | Select-Object
$domain = "example.com"
$domainname = "example.com"

# CREATING CREDENTIALS
[string][ValidateNotNullOrEmpty()] $password = 'very_secret_password'
[SecureString] $password = ConvertTo-SecureString -String $password -AsPlainText -Force
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "_ad_username_",$password

Add-Computer -ComputerName $current_hostname -DomainName $domainname -Credential $credential -Restart -Force

# File Sharing

On Windows server, you need to enable File and Printer Sharing feature.

# ENABLE FILE SHARING
netsh advfirewall firewall set rule group="File and Printer Sharing" new enable=Yes

# Admin Group

Adding a Local user to the Administrator Group

# ADD USER TO ADMIN
Add-LocalGroupMember -Group "Administrators" -Member user_name

# Download File

Powershell command to download file

$url = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
$output = "C:\Users\jack_oneil\Desktop\nuget.exe"
Invoke-WebRequest -Uri $url -OutFile $output

# DNS Server

Configure the network interface with a specific DNS Server.

# Get the network interface configuration details
Get-NetIPConfiguration
Set-DnsClientServerAddress -InterfaceIndex 8 -ServerAddresses ("8.8.8.8")

# AWS S3

Read-S3Object -BucketName s3-bucket-name -Key "windows/2019/symantec_dc/setup.exe" -File "c:\tools\symantec_dc/setup.exe"

# Hostname

Rename Computer name on Windows Server

Rename-Computer -NewName pascal-windows-test -Force

# Dummy file

Create dummy file for testing

# CREATE DUMMY FILE - CMD
echo "This is just a sample line appended  to create a big file. " > dummy.txt
for /L %i in (1,1,21) do type dummy.txt >> dummy.txt

# Check installed app

Check if an application has been installed

(gp HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*).DisplayName -Contains "app_name"

# Check if process

Get-Process app_name -FileVersionInfo

# Get public IP

Example of how to get the public ip address

# Option 1
curl -Uri http://checkip.amazonaws.com -UseBasicParsing

# Option 2
Invoke-WebRequest -Uri http://checkip.amazonaws.com -UseBasicParsing

# Check listening ports

Get-NetTCPConnection -State Listen