PowerShell: The most important commands for administrators

With the PowerShell, administrators can quite easily perform many tasks that are necessary for daily operations.

Also, for better privacy in Windows 10, commands from the PowerShell can help. In this article, we will show you some PowerShell commands that administrators should know.

1. Windows 10 Privacy: Disable and monitor Windows tasks in the PowerShell

Windows 10 periodically sends information over the Internet to Microsoft. Many of the transfers perform Windows as a scheduled task.

An example is the task “Customer Experience Improvement Program (CEIP)”. To stop this service, use the following command:

Disable-ScheduledTask -TaskName “\ Microsoft \ Windows \ Customer Experience Improvement Program \ KernelCeipTask”.

The corresponding commands can also be stored in networks with Active Directory via PowerShell scripts as logon scripts. You can check the status of the services with

get-ScheduledTask

Show. Here, the name of the task is sufficient for querying; you do not have to specify the complete path.

2. Control printers and print jobs in the PowerShell

Administrators can resolve problems with printers in PowerShell on servers, workstations, but also on Remote Desktop Session Hosts. You can use the installed printers with

get-printer

call. Here you can also see which drivers are used for the printers. All print jobs on a server or computer can be used

get-printer | get-printjob | fl

Show.

For example, to display a list that shows the location, name, and status, use:

Get-Printer | fl Name, Location, PrinterStatus

If you want to delete print jobs, use the cmdlet

Remove print job.

Here, too, you have the option of filtering and deleting the print jobs of individual printers:

Remove-PrintJob -PrinterName “Samsung” ID 1

The PowerShell can also show which users started a print job. If you wish, PowerShell allows you to delete the print jobs of a specific user for all printers in the company. This too is much faster in PowerShell than with graphical tools:

Get-Printer | Get-PrintJob | where UserName -LIKE <username> | Remove-Print Job

Also interesting in this area are:

Restart-PrintJob – Restarts a print job

Resume-PrintJob – Continues a print job

3. Different ways to network access with the PowerShell

There are several ways to run PowerShell commands over the network. First, you can use the PowerShell or PowerShell ISE normal CMDlets with the -computername option. In this case, the local PowerShell session is used, but the PowerShell sends the command over the network to the destination server. With the command

Get-Help * parameter ComputerName

get a list of all these cmdlets.

The second option is to open a PowerShell session on the remote server directly in PowerShell or PowerShell ISE. Any commands that you run in this session will then run on the remote computer. In this case, the -computername option is not necessary because the session is already running on the remote computer anyway.

To start programs from a local PowerShell session over the network on a remote computer, use the following command:

Invoke-Command -ComputerName <target computer> -ScriptBlock {<command>} -credential <username>

If the command works, an authentication window opens and you must enter the password for the user.

With the CMDlet

Test WsMan <computer name>

test the access. If you do not receive an error message, but a progress bar, access from the source computer to the target computer will work.

In the PowerShell ISE, it’s easiest to open remote sessions. To do this, go to File \ New Remote PowerShell tab, enter the server name, and credentials for the server. All commands that you run in this session are started on the remote computer.

To create a remote session in the regular PowerShell, enter the New-PSSession cmdlet. With

Enter PSSession <server name>

build a connection. If you want to authenticate with another user, use

Enter-PSSession -ComputerName <Computer> -Credential <user>.

With exit session, you end this session again. You can also break and rebuild sessions in Windows Server 2012 R2 and Windows 8.1. For interrupted sessions, the cmdlets continue to run in the session. To do this, use the cmdlets

Disconnect PSSession, Connect PSSession

Receive-PSSession.

Read Also: 10 most important Linux commands for beginners

4. Unattended installation of roles and features

In addition to being able to install roles and features through PowerShell by specifying the name of the role and feature, you can also use the XML control file in PowerShell, which you can save in the New Roles Wizard in the last window,

To install the same roles and features on another server, use PowerShell and include the XML file. You use the cmdlet

Install Windows Feature

with the -ConfigurationFilePath option, for example

Install-WindowsFeature -ConfigurationFilePath C: \ Data \ iis.xml.

5. Update management in the PowerShell

To manage updates in the PowerShell via scripts, use the free PowerShell module “Windows Update PowerShell Module”.

Copy the PSWindowsUpdate directory from the archive to the% WINDIR% \ System32 \ WindowsPowerShell \ v1.0 \ Modules directory.

Open the Windows PowerShell and let the module load with import modules PSWindowsUpdate. Then the CMDlets are available. The following are part of the module:

• Add-WUOfflineSync
• Add-WUServiceManager
• Get-WUHistory
• Get-WUInstall
• Get-WUInstallerStatus
• Get-WUList
• Hide-WUUpdate
• Invoke-WUInstall
• Get-WURebootStatus
• Get-WUServiceManager
• Get-WUUninstall
• Remove-WUOfflineSync
• Remove-WUServiceManager
• Update-WUModule

6. Monitor system processes in the PowerShell

A common administration task is managing the running processes on a server. About the command

Get-Process

You can view all running processes of a computer.

If you want to display all processes with the initial letter “S”, issue the command

Get-process s *

on. If the processes are to be sorted additionally, for example, descending according to the CPU time, enter

Get-process s *

followed by the pipe option

| Sort-Object cpu -Descending

on.

7. Use WMI queries

With Windows servers, you also have the option of querying or scripting information via the Windows Management Interface.

For example, you can configure the paging file configuration from the command line through WMI.

It is not necessary to deal with the complex WMI issue, but with the PowerShell this data can be read quickly and easily.

Detailed information about hard disks can be obtained, for example, using WMI commands. There is the CMDlet for this

Get-WmiObject.

Use the Win32_LogicalDisk option to display very detailed information about disks.

If you want to see the installed operating system and the date of installation, you can also use WMI and PowerShell. With the command

get-wmiobject win32_operating system | select @ {name = “Installed”; Expression = {$ _. ConvertToDateTime ($ _. InstallDate)}}, Caption display the corresponding information.

Also, the bit variant of the operating system (Get-WmiObject -Class Win32_ComputerSystem -ComputerName. | Select-Object -Property SystemType), domain, vendor, model, and more (Get-WmiObject -Class Win32_ComputerSystem) can be viewed.

8. Exporting and importing the configuration of the start page in the PowerShell – Specify start page layout

In Windows 8.1 / 10, you can use the cmdlet

Export Start Layout

in PowerShell, export the look and configuration of the Home and Start menus to a file. You can also use this function to specify on local computers what the start page should look like.

To do this, first customize the start page or the start menu and export them as an XML file. You store the configuration file with the users as a standard page or standard start menu.

In this way you can either remove all apps from the home page and the start menu, or integrate the apps on the home page and the start menu that users should be able to use.

Distribution is also possible through Group Policy with Windows Server 2012 R2. To export the current layout, enter the following command:

Export-StartLayout -path <path to XML file> -As XML

Administrators in corporate networks can prohibit changes to the home page. There is also the option Start page layout in the guidelines of Windows 8.1 / 10 and Windows Server 2012 R2. These can be found in the Group Configuration under User Configuration / Administrative Templates / Start Menu and Taskbar. In this area, you can save the layout file that you previously created with the new cmdlet

Export Start Layout have exported. This also works for local machines and local policies.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top