Random PowerShell tidbits19 Jun 2018
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:
Change DNS address for all Ethernet interfaces
Get-NetAdapter -InterfaceAlias "Ethernet*" | Set-DnsClientServerAddress -ServerAddresses ("22.214.171.124")
Note: This will configure all interfaces that have “Ethernet” listed in the name. You can narrow this search by using Get-NetAdapter.
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.
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.
Rename a computer
Rename-Computer -NewName "windows-2016.orangutan.lab"
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