Powershell executes external commands

Source: Internet
Author: User

Powershell Execution External Command 7
24 November, 2011 in PowerShell Tagged PowerShell tutorial/program by Mooser Lee
This article index
Hidden
1 Viewing network port status via netstat
2 Viewing your network configuration with ipconfig
3route Print View routing information
4 starting the CMD console
5 Find the available cmd console commands
6 Starting an external program
Powershell is able to execute external commands as well as CMD.

View network port status via netstat

PS c:\ps> Netstat

Active Connections

Proto Local address Foreign address state
TCP 192.168.0.100:3049 192.168.0.88:7575 established
TCP 192.168.0.100:3052 192.168.0.88:7575 established
TCP 192.168.0.100:3061 192.168.0.88:7575 established
View your network configuration with ipconfig

PS c:\ps> ipconfig

Windows IP Configuration

Ethernet Adapter Local Area Connection:

Connection-specific DNS Suffix. : www.mossfly.com
Link-local IPv6 Address .....: fe80::b9dd:91e33:33f0:7885%10
IPv4 the Address ..... : 192.168.140.100
Subnet Mask ........... : 255.255.252.0
Default Gateway ..... . : 192.168.140.1

Tunnel Adapter Isatap.www.mossfly.com:

Connection-specific DNS Suffix. : www.mossfly.com
Link-local IPv6 Address .....: fe80::5efe:192.168.140.100%11
Default Gateway ..... . :

Tunnel Adapter Teredo Tunneling Pseudo-Interface:

Media State ........... : Media Disconnected
Connection-specific DNS Suffix. :
Route Print View routing information

PS c:\ps> Route print
IPv4 Route Table
================================================================ ===========
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 192.168.140.1 192.168.140.100
192.0.0.0 255.0.0.0 on-link 192.0.0.1 306
192.0.0.1 255.255.255.255 on-link 192.0.0.1 306
1 92.255.255.255 255.255.255.255 on-link 192.0.0.1 306
192.168.140.0 255.255.252.0 on-link 192.168.140.100 276
192.168.140.100 255.255.255.255 on-link 192.168.140.100 276
192.168.143.255 255.255.255.255 on-link 192.168.140.100 276
224.0.0.0 240.0.0.0 on-link 192.0.0.1 306
224.0.0.0 240.0.0.0 on-link 192.168.140.100 276
255.255.255.255 255.255.255.255 on-link 192.0.0.1 306
255.255.255.255 255.255.255.255 on-link 192.168.140.100 276< br>===========================================================================
Persistent Routes:
None

IPv6 Route Table
===========================================================================
Active Routes:
If Metric Network Destination Gateway
1 306:: 1/128 On-link
Ten 276 fe80::/64 On-link
281 fe80::5efe:192.168.140.100/128
On-link
Ten 276 fe80::b965:91f3:33a0:7285/128
On-link
1 306 FF00::/8 On-link
Ten 276 FF00::/8 On-link
===========================================================================
Persistent Routes:
None
Start the cmd console

Start the cmd console type cmd or cmd.exe, exit cmd by command exit.

PS c:\ps> cmd
Microsoft Windows [Version 6.1.7601]
Copyright (c) Microsoft Corporation. All rights reserved.

C:\ps>exit
PS c:\ps>
Find the available cmd console commands

Cmd.exe to receive command parameters through/C, help can see the available commands in cmd, so you can find the available cmd console commands by CMD/C Help

PS c:\ps> cmd/c Help
For more information about a command, type the help command name
ASSOC Displays or modifies file name extension associations.
ATTRIB Display or change file properties.
Break sets or clears the extended CTRL + C check.
BCDEDIT set the properties in the startup database to control the boot load.
CACLS displays or modifies the Access Control List (ACL) of the file.
Call calls this one from another batch program.
The CD displays the name of the current directory or changes it.
CHCP Displays or sets the number of active code pages.
CHDIR displays the name of the current directory or changes it.
CHKDSK checks the disk and displays the status report.
CHKNTFS Displays or modifies the startup time disk check.
CLS clears the screen.
CMD opens another Windows command interpreter window.
Color sets the default console foreground and background color.
COMP compares the contents of two or two sets of files.
Compact displays or changes the compression of files on NTFS partitions.
Convert converts a FAT volume to NTFS. You cannot convert
The current drive.
Copy copies at least one of the files to another location.
Date Displays or sets dates.
DEL deletes at least one file.
DIR displays the files and subdirectories in a directory.
DISKCOMP compares the contents of two floppy disks.
DISKCOPY Copy the contents of one floppy disk to another.
DISKPART displays or configures disk partition properties.
DOSKEY Edit the command line, invoke the Windows command, and create a macro.
Driverquery Displays the current device driver status and properties.
echo Displays the message, or turns the command back on or off.
Endlocal to end localization of environment changes in batch files.
ERASE Delete one or more files.
Exit CMD. EXE Program (command interpreter).
FC compares two files or two sets of files and displays the differences between them.
Find searches one or more files for a text string.
FINDSTR searches for strings in multiple files.
For each file in a set of files, run a specified command.
Format formats the disk for use with Windows.
FSUTIL displays or configures the properties of the file system.
FTYPE displays or modifies the file types that are associated with the file name extension.
GOTO to point the Windows command interpreter to a batch program
A labeled row in the
GPRESULT Displays Group Policy information for the machine or user.
GRAFTABL enable Windows to display the extended character set in graphics mode.
Help provides information about Windows commands.
ICACLS display, modify, back up, or restore files and
The ACL for the directory.
IF a conditional process is performed in a batch program.
Label creates, changes, or deletes a disk's volume label.
MD to create a directory.
MKDIR Create a directory.
MKLINK creating Symbolic links and hard links
MODE configures the system device.
More display output per screen.
Move moves one or more files from one directory to another.
OPENFILES displays files opened by remote users for file sharing.
Path displays or sets the search path for the executable file.
Pause stops processing of the batch file and displays information.
POPD restores the previous value of the current directory saved by PUSHD.
Print prints a text file.
PROMPT Change Windows command prompt.
PUSHD Save the current directory and make changes to it.
RD Delete directory.
The RECOVER recovers readable information from the damaged disk.
REM records batch files or CONFIG. The comment in SYS.
REN renames the file.
RENAME Rename the file.
Replace replaces the file.
RMDIR Delete the directory.
ROBOCOPY advanced utilities for copying files and directory trees
Set to display, set, or remove Windows environment variables.
SETLOCAL began to change the localization of the environment with batch files.
SC Display or Configuration service (background processing).
SCHTASKS schedule commands and programs to run on a single computer as scheduled.
SHIFT adjusts the position of replaceable parameters in the batch file.
SHUTDOWN allow the machine to shut down properly locally or remotely.
Sort sorts the inputs.
START opens a separate window to run the specified program or command.
SUBST associates the drive letter with the path.
SYSTEMINFO displays the specific properties and configuration of the machine.
TASKLIST displays all currently running tasks that include the service.
TASKKILL terminates a running process or application.
Time displays or sets the system times.
The TITLE sets CMD. The window caption of the EXE session.
Tree displays the directory structure of the initiator or path graphically.
TYPE Displays the contents of the text file.
VER shows the version of Windows.
VERIFY tells Windows to verify that the file is written to disk correctly.
VOL Displays the disk volume label and serial number.
XCOPY copies files and directory trees.
WMIC displays WMI information in an interactive command shell.
Start an external program

Why can I open Notepad through Notpad and not open WordPad through WordPad?
Because Notepad.exe is located in the C:windows\system32 directory, this directory is already included in the PowerShell environment variable $env:path by default.

C:\WINDOWS\system32; C:\WINDOWS; C:\WINDOWS\System32\Wbem; C:\WINDOWS\System32\WindowsPowerShell\v1.0\; C:\Program Files (x
) \ Windows Kits\8.1\windows performance toolkit\; C:\Program Files\Microsoft SQL Server\110\tools\binn\; C:\Program File
S (x86) \microsoft Sdks\typescript\1.0\; C:\Program Files\microsoft\web Platform Installer\
and Wordpad.exe's "%ProgramFiles%\Windows Nt\accessories\wordpad.exe" directory is not included, you can first enter this directory, then run WordPad, or add the directory where WordPad is located to the environment variable, $env:P ath= $env:P ath+ "%ProgramFiles%\Windows nt\accessories".

By default Type a string, PowerShell will output it as is, if the string is a command or startup program, before the string ' & ' can execute the command, or start the program.

PS c:\ps> "LS"
Ls
PS c:\ps> & "ls"

Directory:c:\ps

Mode LastWriteTime Length Name
---- ------------- ------ ----
D----2011/11/23 17:25 ABC
-A---2011/11/23 17:36 a.txt
-A---2011/11/23 17:25 0 b.txt
-A---2011/11/23 17:25 0 c.txt
-A---2011/11/23 17:25 0 d.txt
-A---2011/11/23 17:37 242 test.txt

PS c:\ps> "cmd.exe"
Cmd.exe
PS c:\ps> & "cmd.exe"
Microsoft Windows [Version 6.1.7601]
Copyright (c) Microsoft Corporation. All rights reserved.
This article link: http://www.pstips.net/powershell-executing-external-commands.html

Powershell executes external commands

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.