Skip to main content

Posts

Showing posts with the label PowerShell

PowerShell Quick Tip: Get alias for a cmdlet

PowerShell Quick Tip: Get alias for a cmdlet Below shows how to get the aliases for Remove-Item cmdlet. PS C:\prj> Get-Alias -Definition Remove-Item CommandType Name Version Source ----------- ---- ------- ------ Alias del -> Remove-Item Alias erase -> Remove-Item Alias rd -> Remove-Item Alias ri -> Remove-Item Alias rm -> Remove-Item Alias rmdir -> Remove-Item

Install PowerShell using winget

(Formerly PowerShell Core) PowerShell is a cross-platform task automation solution made up of a command-line shell, a scripting language, and a configuration management framework. PowerShell runs on Windows, Linux, and macOS. To install PowerShell on Windows using winget , do: PS C:\>winget install Microsoft.PowerShell Note: To install winget on Windows 2022 follow this link .

PowerShell Quick Tip: Change screen resolution from the command line

PowerShell Quick Tip: Change screen resolution from the command line I had a VM that I can't open Display Settings , so had to figure out how to change the screen resolution from the command line. This can also be handy if you have several machines that for some reason has to be running at specified resolution, for example, running UI automated tests. PS C:\>Set-DisplayResolution -Width 1600 -Height 900 Tags:PowerShell, command line, screen resolution

Use Windows Event Log to log events from PowerShell

Windows Event Log is a convenient event store to log information. Once data is in Windows Event log it can be correlated with other information on the system.  There two basic steps to do this: Create log location and source Write log information into that location and source To create log location and source, do: PS C:\> New-EventLog -LogName 8thstring -Source 8thSource Where: 8thstring is the log location 8thSource is the source You have to run this on an elevated PowerShell session. And if you have Windows Event Viewer open, you have to close it and re-open to see the new log. This should show up under Applications and Service Logs .  To write to that log location and source, do: PS C:\> Write-EventLog -LogName 8thstring -Source 8thSource -Message "Hello world" -EventId 0 -EntryType information Where: -LogName 8thstring //8thstring was created using New-EventLog above -Source 8thsource //8thSource was also created as part of New-EventLog call above - Mess

PS Quick Tips: Change Primary DNS Server of a network interface

PS c:\> Set-DnsClientServerAddress -InterfaceIndex 10 -serveraddresses ("192.168.137.1") Where: 10 - is the interface index. This can be found by running Get-NetAdpater , this will be the column named ifIndex . ("192.168.137.1") - is the DNS server address(es) you want to assign to that interface, this is a comma separated list. Note: This only works on Powershell 3 (or maybe later). Reference(s): http://4sysops.com/archives/how-to-configure-a-network-interface-card-nic-with-powershell-3/

Enable ClearType using PowerShell

When I remote desktop to Windows machines most of the time the fonts just looks ugly. This can be improved by enabling ClearType and I do this every time I connect to a box which I do several times a day. Below is a Powershell code that enables ClearType which I shamelessly copied from StackOverflow. Reference(s): http://stackoverflow.com/questions/5676768/enable-disable-cleartype-in-windows7

Disable/Enable network interface using PowerShell

Windows 10 update 1511 sometimes losses connection inside a VirtualBox(5.0.16) VM. Mostly it happens after the host machine recovers from sleep or hibernate. Workaround I have observed so far is to disable/enable the interface. This can get boring overtime, so below is the PowerShell script that I use to automate it. Note that O is the name of my network adapter.