Microsoft PowerShell Command Guide – Part 1

As PowerShell become more and more important tool in our day to day administration I have put up most of the basic commands that are being used by administrators and engineers.

Part 1 will give cover the basic commands and what they are doing.

Part 1

Terms

Cmdlets – command built into PowerShell

Get command – this command show us information about an item

Set command – this is the modifying command

; – semicolon commands

>> – append to existing file

Alias – create shortcut to a command

Basic Commands

Cd – open dir

Dir – show working directory

Md – make \ create a directory

Pwd – show path

Rmdir – remove directory

Mkdir – create directory

Display command

Format-table

Format-list

Format-wide

Get – command

Get-process – show running process

Get-process processname – check specific process name

Get-process name* – will search for a process start with the name

Stop-process -id number – stop a process

Whatif – tell you what heppan before you run a cmdlet

Sample Stop-process -id number – whatif – stop a process

-confirm – ask for conformation before executing a command

Get-help – help command

Get-eventlog – show event log

Samples and Commands

Ipconfig \all > ipconfig.txt – Pipe result to text file

Notepad ipconfig.text – Launch file to screen

Piping a few commands

ipconfig /all > test.txt ; route print >> test.txt

Help Commands

Get-help get-help – help command

Get-help get* – will show all the get commands

Get-help set* – will show all the set commands

Get-help * – show all commands

Get-help get-psdrive –example – show you the syntax

Get-commands – display all the get commands

Alias

Get-alias – show all alias in use

Set-alias – create an alias

Get-alias |sort – sort all alias names

Set Alias

Set-alias gh get-help – set gh as an alias to get-help

How To Set Session Timeout On A Cisco Router

Setting the session timeout parameter in a cisco router or switch is an easy task that will make your day to day work easy.

How to set the session timeout:

log on to the router and type:

router#configure t

router(config)#line vty 0 4

router(config-line)#session-timeout 10       —- 10 is the amount of minutes we want to configure before timeout.

router(config-line)#exec-timeout 0                    — this is when we log in exec mode ( 0 is never)

router(config-line)#end                                      –  exit the config line mode

router#copy run start

router#copy run start

Create New User \ Mailbox Script Using Exchange 2007 Shell

With Exchange 2007 we have the option to manage our Exchange Server using the Exchage Managment shell which done using commands (cmdlts).

This script is for creating a single user mailbox and an AD user using the shell.

The script called newuser.ps1

Just copy and save the file as newuser.ps1 and don’t forget to change the server and OU details.

$UPN=Read-Host “upn”                 -System.String
$Alias=Read-Host “Alias”              -asPlainText
$Name=Read-Host “Enter Name”   -asPlainText
$Password=Read-Host “Enter Password” -AsSecureString

new-mailbox -userPrincipalName $upn -alias $alias -name $name  -database “exchange server name\Mailbox Database name”  -OrganizationalUnit ‘yourdomain/your_ou_name’ -Password $Password

————

The script will ask you to provide a password,Alias,name and UPN (the email address).

How To Print Screen In RDP Session

In order to print screen a window in an RDP session we need to use a different keys than the ones we use on our local desktop.

To print screen in RDP session please use:

CTRL+ALT+MINUS (–) symbol on the numeric keypad.

GPRESULT In Windows Server 2008

Microsoft have made a small change to the Windows Server 2003 GPRESULT command.

In windows 2003 we had to type GPRESULT only in the command line in order to view the Applied Group polices however in windows server 2008 we need to type the /R switch after the gpresult.

The windows Server 2008 the full GPRESULT command is:

gpresult /s

there are other switches to the command which are:

s <Computer> Specifies the name or IP address of a remote computer. Do not use backslashes. The default is the local computer.
/u [<Domain>\]<UserName> Runs the command with the credentials of the specified user. The default user is the user who is logged on to the computer that issues the command.
/p [<Password>] Specifies the password of the user account that is provided in the /u parameter. If /p is omitted, gpresult prompts for the password. /p cannot be used with /x or /h.
/user [<TargetDomain>\]<TargetUser> Specifies the remote user whose RSoP data is to be displayed.
/scope {user | computer} Displays RSoP data for either the user or the computer. If /scope is omitted, gpresult displays RSoP data for both the userand the computer.
[/x | /h] <FileName> Saves the report in either XML (/x) or HTML (/h) format at the location and with the file name specified by the FileName parameter. Cannot be used with /u, /p, /r, /v, or /z.
/f Forces gpresult to overwrite the file name specified in the /x or /h option.
/r Displays RSoP summary data.
/v Displays verbose policy information, including additional detailed settings that have been applied with a precedence of 1.
/z Displays all available information about Group Policy, including detailed settings that have been applied with a precedence of 1 and higher.
/? Displays help at the command prompt.

For more information see:

http://technet.microsoft.com/en-us/library/cc733160.aspx

Limit the Number Of allowed IPSEC VPN sessions on Cisco ASA 5540

To set a limit on the number of allowed IPSEC VPN session on an Cisco ASA 5540 we need to define how many sessions \ users are allowed to be connected to the ASA in each given time.

By default the number of allowed VPN session is unlimited.

To set a limit we need use the Cisco ASDM.

Once logged to the ASDM go to:

Configuration > remote access VPN > Network (client) access > advanced > IPsec > System options

Once there change the maximum IPsec sessions, to the applicable number.

How To Check Which interfaces are Enabled Or Disabled On A Cisco Switch

To check which ports are active or disable on a Cisco switch we need to use the status command and follow the steps below.

1. Log on to the router.
2. Type “show interfaces status” command

Example:
SWITCH1#sh interfaces status
Port      Name               Status       Vlan       Duplex  Speed Type
Gi0/1                        connected    24         a-full a-1000 10/100/1000BaseTX
Gi0/2                        connected    24         a-full a-1000 10/100/1000BaseTX
Gi0/3                        disabled     24           auto   auto 10/100/1000BaseTX
Gi0/4                        disabled     24           auto   auto 10/100/1000BaseTX
Gi0/5                        disabled     24           auto   auto 10/100/1000BaseTX
Gi0/6                        connected    24         a-full  a-100 10/100/1000BaseTX
Gi0/7                        connected    23         a-full a-1000 10/100/1000BaseTX
Gi0/8                        connected    23         a-full  a-100 10/100/1000BaseTX
Gi0/9                        connected    22         a-full a-1000 10/100/1000BaseTX
Gi0/10                       notconnect   1            auto   auto 10/100/1000BaseTX
Gi0/11                       connected    27         a-full a-1000 10/100/1000BaseTX
Gi0/12                       connected    26         a-full a-1000 10/100/1000BaseTX
Gi0/13                       disabled     26           auto   auto 10/100/1000BaseTX
Gi0/14                       connected    26         a-full  a-100 10/100/1000BaseTX
Gi0/15                       connected    22         a-full a-1000 10/100/1000BaseTX
Gi0/16                       notconnect   27           auto   auto 10/100/1000BaseTX
Gi0/17                       connected    22         a-full a-1000 10/100/1000BaseTX
Gi0/18                       notconnect   25           auto   auto 10/100/1000BaseTX
Gi0/19                       connected    25         a-full a-1000 10/100/1000BaseTX
Gi0/20                       connected    25         a-full a-1000 10/100/1000BaseTX
Gi0/21                       disabled     1            auto   auto Not Present
Gi0/22                       disabled     1            auto   auto Not Present
Gi0/23                       connected    trunk      a-full a-1000 1000BaseLX SFP
Gi0/24                       connected    trunk      a-full a-1000 1000BaseLX SFP
Po1                          connected    trunk      a-full a-1000
 
In order for us to enable or disable a port on a Cisco switch do the following:
To Enable a Port Type:
SWITCH1# int Gi0/2
SWITCH1# no shutdown

To disable a port Type:
SWITCH1#int Gi0/2
SWITCH1#shutdown\0

How to block A Sander In Exchange Server 2007

To block a sander in Exchange server 2007 never been easier, all you have to do is add the the sander to the Exchange Server 2007 Anti Span built in function.

To do that:

  1. Log In to the Exchange Management Console, click Edge Transport.
  2. Click on the Anti-spam tab, and double click on Sender Filtering.
  3. Click the Blocked Senders tab, and then click Add.

 select the Individual e-mail address option, and then type the e-mail address.

4.       Click Apply to save your changes.

 

How To Configure A Cisco Router Or Switch to Send Logs To A SysLog Server

If you would like to configure you Cisco Router or switch to send all it’s logs to a SysLog server all you have to do is to type a few command that will tell the router\switch to send the logs to the server.

To do that:

Log to the router \ switch and type (in this example I used a switch):

SWITCH# Config t
SWITCH(config)#logging 172.40.51.44   — SysLog IP address
SWITCH(config)#logging trap notifications  — What do you want to send
SWITCH(config)#logging source-interface ?   — Interface that will send the logs
  Async              Async interface
  Auto-Template      Auto-Template interface
  BVI                Bridge-Group Virtual Interface
  CTunnel            CTunnel interface
  Dialer             Dialer interface
  Filter             Filter interface
  Filtergroup        Filter Group interface
  GigabitEthernet    GigabitEthernet IEEE 802.3z
  GroupVI            Group Virtual interface
  Lex                Lex interface
  Loopback           Loopback interface
  Null               Null interface
  Port-channel       Ethernet Channel of interfaces
  Portgroup          Portgroup interface
  Pos-channel        POS Channel of interfaces
  Tunnel             Tunnel interface
  Vif                PGM Multicast Host interface
  Virtual-Template   Virtual Template interface
  Virtual-TokenRing  Virtual TokenRing
  Vlan               Catalyst Vlans
  fcpa               Fiber Channel

SWITCH(config)#logging source-interface vlan2�
SWITCH(config)#exit
All done, don’t forget to save the config.

ROUTER(config)#copy run start.