Pages

Showing posts with label Powershell. Show all posts
Showing posts with label Powershell. Show all posts

Saturday, 29 September 2012

Install PowerShell v3 on Windows 7

Just a quickie:

  1. You will need .NET Framework 4.0. That’s the full thing not just the ‘client profile’ that you might see in add-remove programs. To get this : http://go.microsoft.com/fwlink/?LinkID=212547
  2. On your Windows 7 box make sure you got SP1: http://www.microsoft.com/en-us/download/details.aspx?id=5842
  3. You can download the PowerShell v3 (Windows Management Framework 3.0) here: http://www.microsoft.com/en-us/download/details.aspx?id=34595#system-requirements

Monday, 16 May 2011

Enable PowerShell Remoting While Running VMWare Workstation in a Domain

After trying to configure WinRM I received the following error:

winrm1

To avoid this I found the following link very usefull

Wednesday, 30 March 2011

Using the Powershell to Send Email Messages (Send-MailMessage)

With Exchange 2007 SP2 you can send emails from within powershell! To avoid authentication issues, your default receive connector must allow anonymous users to connect. This is normally required when you allow connections to your exchange server from the Internet. You can do this from the shell:

To determine your connector name:

[PS] Get-ReceiveConnector

This will provide the following output (EX1 being the name of my exchange server)

Identity Bindings Enabled

-------- -------- -------
EX1\Default EX1 {:::25, 0.0.0.0:25} True

EX1\Client EX1 {:::587, 0.0.0.0:587} True
 
Now you can determine the current permissions set on the Default connector:
 
[PS] Get-ReceiveConnector "EX1\Default EX1" ft name,perm* -au
 
This will provide the current permissions set on the connector. If the connector has not been configured to receive mail from the Internet, then you will most likely NOT see "Anonymous" listed. This will need to be included. You can do this as follows:
 
[PS] Get-ReceiveConnector "EX1\Default EX1" |Set-ReceiveConnector -PermissionGroups AnonymousUsers, ExchangeUsers, ExchangeServers, ExchangeLegacyServers
 
Once this is done, you can send email from the powershell. Here's an example where the administrator (user currently running powershell) sends an email to a recipient (usermailbox) called ben:
 
[PS] Send-MailMessage -From administrator@compulinx.local -To ben@compulinx.local -Subject "Test Email" -Body "Hi Ben ...Just a test" -SmtpServer ex1.compulinx.local

Sunday, 20 February 2011

Remote Powershell

On my travels I picked up this useful method of remoting into another machines powershell. Windows 7 and Server 2008 R2 have WinRm packed inside so you dont need to download anything. If your not sure you can try typing the following:

[PS] Get-Service winrm

On the server you want to remote into (lets call it the target), type the following:

[PS] Enable-PSRemoting

This command will start the WinRM service and sets the startup type to Automatic.  It will also enables a firewall exception for WS-Management communications and create a listener to accept requests on any IP address.
The next step involves establishing which machines can connect to the target (that is your client). On the target type the following:

[PS] cd wsman:
(note the colon:)
[PS] cd localhost\client
[PS] dir

You should see a table displayed indicating that the TrustedHosts has a no value. This has to be changed so that your client can connect. To do this type the following but note you MUST be in the WSMan namespace as shown above!

[PS] Set-Item TrustedHosts *

You should then restart the WinRm service

[PS] Restart-Service winrm 

You could have performed the action by typing one single cmdlet:

[PS] Set-Item WSMan:\localhost\Client\TrustedHosts *


Now that your target is configured, you need to configure the client. Type the following:

[PS] New-PSSession -computername "FQDN of the Target"

You should now see a table displayed referencing your session with an ID number. To display the session created at any time type the following:

[PS] Get-PSsession

To enter the session type the following:

[PS] Enter-PSsession -id (the numerical value of the session e.g. 1)

You should now be in the remote powershell! To end the session type the following:

[PS] Exit-PSsession

and to remove the seesion entirely type the following:

[PS] Remove-PSsession