 |
 |
| Windows Server Tips: |
|
 |
 |

WINDOWS SYSTEMS AND NETWORK ADMINISTRATION
Top 25 Windows PowerShell commands for administrators
Jonathan Hassell, Contributor 09.01.2009
Rating: -4.08- (out of 5)




|
Even though Windows PowerShell has been around for a while, administrators who are brushing up on their command line skills may be interested in understanding the fundamentals of its capabilities.
Let's take a look at 25 very common tasks you can accomplish with Windows PowerShell. Not only are the tasks themselves common, but the structures of the commands show off the syntax and structure of other PowerShell commands, as well. These basic commands should get you started on the path to becoming a PowerShell master.
Common entries (just to get started)
- Navigate the Windows Registry like the file system -- cd hkcu:
- Search recursively for a certain string within files -- dir –r | select string "searchforthis"
- Find the five processes using the most memory -- ps | sort –p ws | select –last 5
- Cycle a service (stop, and then restart it) like DHCP -- Restart-Service DHCP
- List all items within a folder -- Get-ChildItem – Force
- Recurse over a series of directories or folders -- Get-ChildItem –Force c:\directory –Recurse
- Remove all files within a directory without being prompted for each -- Remove-Item C:\tobedeleted –Recurse
- Restart the current computer -- (Get-WmiObject -Class Win32_OperatingSystem -ComputerName .).Win32Shutdown(2)
Collecting information
- Get information about the make and model of a computer -- Get-WmiObject -Class Win32_ComputerSystem
- Get information about the BIOS of the current computer -- Get-WmiObject -Class Win32_BIOS -ComputerName .
- List installed hotfixes (QFEs, or Windows Update files) -- Get-WmiObject -Class Win32_QuickFixEngineering -ComputerName .
- Get the username of the person currently logged on to a computer -- Get-WmiObject -Class Win32_ComputerSystem -Property UserName -ComputerName .
- Find just the names of installed applications on the current computer -- Get-WmiObject -Class Win32_Product -ComputerName . | Format-Wide -Column 1
- Get IP addresses assigned to the current computer -- Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName . | Format-Table -Property IPAddress
- Get a more detailed IP configuration report for the current machine -- Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName . | Select-Object -Property [a-z]* -ExcludeProperty IPX*,WINS*
- To find network cards with DHCP enabled on the current computer -- Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "DHCPEnabled=true" -ComputerName .
- Enable DHCP on all network adapters on the current computer -- Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=true -ComputerName . | ForEach-Object -Process {$_.EnableDHCP()}
Software management
- Install an MSI package on a remote computer -- (Get-WMIObject -ComputerName TARGETMACHINE -List | Where-Object -FilterScript {$_.Name -eq "Win32_Product"}).Install(\\MACHINEWHEREMSIRESIDES\path\package.msi)
- Upgrade an installed application with an MSI-based application upgrade package -- (Get-WmiObject -Class Win32_Product -ComputerName . -Filter "Name='name_of_app_to_be_upgraded'").Upgrade(\\MACHINEWHEREMSIRESIDES\path\upgrade_package.msi)
- Remove an MSI package from the current computer -- (Get-WmiObject -Class Win32_Product -Filter "Name='product_to_remove'" -ComputerName . ).Uninstall()
Machine management
- Remotely shut down another machine after one minute -- Start-Sleep 60; Restart-Computer –Force –ComputerName TARGETMACHINE
- Add a printer -- (New-Object -ComObject WScript.Network).AddWindowsPrinterConnection("\\printerserver\hplaser3")
- Remove a printer -- (New-Object -ComObject WScript.Network).RemovePrinterConnection("\\printerserver\hplaser3 ")
- Enter into a remote PowerShell session (you must have remote management enabled) -- enter-pssession TARGETMACHINE
- Run a script on a remote computer -- invoke-command -computername machine1, machine2 -filepath c:\Script\script.ps1
|
Jonathan Hassell is an author, consultant and speaker residing in Charlotte, N.C. Jonathan's books include RADIUS, Learning Windows Server 2003, Hardening Windows and most recently Windows Vista: Beyond the Manual. | |
 |

|
Rate this Tip
|
To rate tips, you must be a member of SearchWindowsServer.com. Register now
to start rating these tips. Log in if you are already a member.
|


');
// -->
DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.
|
 |
|
|
 |
|
 |
 |
 |
 |
| TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of . |
|
| |
All Rights Reserved, , TechTarget |
|
|
|
|
|