Cody Bunch Some Random IT Guy - OpenStack, DevOps, Cloud, Things

Random PowerShell tidbits

Random Useful PowerShell

I’ve needed to use a few PowerShell commands over and over a few times in the last week or two. So that I do not otherwise forget them again, here they are:

Networking

Change DNS address for all Ethernet interfaces

Get-NetAdapter -InterfaceAlias "Ethernet*" | Set-DnsClientServerAddress -ServerAddresses ("4.2.2.2")

Note: This will configure all interfaces that have “Ethernet” listed in the name. You can narrow this search by using Get-NetAdapter.

Set MTU

Get-NetIPInterface -InterfaceAlias "Ethernet*"| Set-NetIPInterface -NlMutBytes 1450

Note: This will configure all interfaces that have “Ethernet” listed in the name. You can narrow this search by using Get-NetIPInterface.

Disable firewall

Set-NetFirewallProfile -Profile '*' -Enabled False

Note: This is generally considered a bad idea. You can get a lot more specific with Set-NetFirewallProfile, and I suggest you do.

Host management

Rename a computer

Rename-Computer -NewName "windows-2016.orangutan.lab"

Enable WinRM

Enable-PSRemoting -SkipNetworkProfileCheck -Force

Note -SkipNetworkProfileCheck <- This saved me quite a bit of heartache. PSRemoting can be rather flaky, the -SkipNetworkProfileCheck flag made it somewhat less so.

Test WinRM to remote box

$so = New-PSSessionOption -SkipCACheck -SkipCNCheck

Enter-PSSession -Computername 10.127.16.74 -Credential "vagrant" -UseSSL -SessionOption $so
Get-IPAddress -IPAddress "10.*"

Change service startup to automatic

Get-Service -DisplayName "Cloudbase*" | Set-Service -StartupType Automatic