DRIVE EFFICIENCY THROUGH AUTOMATED IT.
SAVE COST THROUGH CONSOLIDATION OF IT.
WANT TO KNOW MORE ABOUT STRATEGIC CONSULTING CLICK HERE.
MICROSOFT / RISUAL HYPER-V CLOUD EVENT 22ND MARCH 2011 CLICKHERE.

Archive

Posts Tagged ‘Powershell’

Running Exchange PowerShell as Scheduled Task

December 1st, 2011 paulw Comments off

If you want to run any of the Exchange PowerShell commands from a standard PowerShell environment then you simply need to add in the following line in order to run it as if it is an Exchange Management Console:

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010

For example, the script below will output the size of the Exchange Databases to a file and can be run as a scheduled task:

 

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010

Get-MailboxDatabase –Status | fl name, databasesize | out-file C:dbsize.txt

 

What we can do then is save the above script to a .ps1 file and then edit the action to start PowerShell.exe and put the arguments as the script that you want to run:

image

This can be set up with the usual Scheduled Task settings and with the PowerShell snap-in for Exchange added in should be able to use the Exchange PowerShell commands.

Cheers

Paul

Importing Users using PowerShell

November 3rd, 2011 paulw Comments off

We had a request from on of our clients where they wanted to create new user accounts for around 50 new employees. In order to do this we created a simple PowerShell script that used a populated CSV file to create the users in a certain OU and with a default password.

The CSV file had the following headings:

image

After saving it to a location we ran the following PowerShell script that created the users:

 

import-module activedirectory
$inputFile = Import-CSV  C:usersToBeCreated.csv

foreach($line in $inputFile)
{
new-aduser -SamAccountName $line.UserName -Name $line.FullName -AccountPassword (ConvertTo-SecureString -AsPlainText "Password" -Force) -Enabled $true -Path "OU=Domain Users,DC=TEST,dc=LOCAL" -DisplayName $line.FullName -GivenName $line.FirstName -Surname $line.SurName -UserPrincipalName $line.UserPrincipalName -ChangePasswordAtLogon $True
}

 

You can copy and paste the script above where you will only need to change the bold text which is the CSV location, the temporary password for the new users and the OU that you want to put the users into.

As long as you use the same headings in your CSV file then this should work ok. You can, of course add in more details that are accepted by the new-aduser command which are outlined in the URL below:

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

Cheers

Paul

Categories: Uncategorized Tags:

Remote Reboot via PowerShell

August 19th, 2011 Jovan Davis Comments off

Below is PowerShell command which can be run to force a reboot on a remote machine:

(gwmi win32_operatingsystem -ComputerName ComputerName -cred (get-credential)).Win32Shutdown(6)

Categories: Uncategorized Tags: ,

Record your PowerShell session

August 10th, 2011 Daniel Davies Comments off

There is a quick way to record your session in PowerShell to a text file so you have a record of every command you have typed.

In PowerShell run the following command (Change location to wherever you would like)

Start-Transcript c:Powershell.txt –Append

Now use PowerShell as you usually would, once you have finished with PowerShell run the following command “Stop-Transcript”

If you now open the “PowerShell.txt” you will see everything you have just done in your PowerShell session.

**********************
**********************
Windows PowerShell Transcript Start
Start time: 20110810173323
Username  : Test
Machine      : Test (Microsoft Windows NT 6.1.7600.0)
**********************
Transcript started, output file is c:MySession.txt
[PS] C:>Get-Mailbox –Identity Dan

Name                     Alias                ServerName
—-                         —–                 ———-
Dan                        Dan                  Test

[PS] C:>Get-User -Identity risual

Name               RecipientType
—-                   ————-
Dan                  UserMailbox

[PS] C:>Stop-Transcript

Categories: Uncategorized Tags: ,

Remote Shutdown via PowerShell

July 11th, 2011 Jovan Davis Comments off

Below is PowerShell command which can be run to force shutdown on a remote machine:

(gwmi win32_operatingsystem -ComputerName ComputerName -cred (get-credential)).Win32Shutdown(5)

Categories: Uncategorized Tags: ,

Exchange 2010 Mailbox Sizes in One Command

June 22nd, 2011 paulw Comments off

Here is a good command to use if you want to find out the size of all your mailbox databases in Exchange 2010:

Get-MailboxDatabase –Status | fl name, databasesize

It should output something similar to this:

image

You can simply copy and paste the above command into an Exchange 2010 PowerShell window and run. Hope this helps.

Paul

Enable/Disable a Service via PowerShell

June 13th, 2011 Daniel Davies Comments off

Here’s a few quick PowerShell commands that will allow you to Disable or Enable a Service and Start or Stop a particular service.

To Enable a particular service run the following command. (Please Edit ServiceName to the desired service)

Set-Service ServiceName -StartupType Automatic

To Disable a particular service run the following command.

Set-Service ServiceName -StartupType Disabled

To Stop a particular service run the following command.

Stop-Service ServiceName

To Start a particular service run the following command.

Start-Service ServiceName

You can also combine the commands in a ps1 file , for example if you want to Disable and Stop a Service you would run the following.

“Set-Service ServiceName -StartupType Disabled
Stop-Service ServiceName”

Categories: Uncategorized Tags: ,

Force Logoff on Remote Machine Via PowerShell

June 8th, 2011 Daniel Davies Comments off

Just a quick command here to logoff remote machines via PowerShell

“(gwmi win32_operatingsystem -ComputerName ComputerName -cred (get-credential)).Win32Shutdown(4)”

This will log every user off the machine specified above.

Categories: Uncategorized Tags: ,

Run PowerShell Script Remotely

June 2nd, 2011 Daniel Davies Comments off

If you have PowerShell 2.0 installed on machines in your environment, then you are able to execute PowerShell scripts on remote machines straight from your local machine.

First make sure you enable remote script execution on your Local and Remote machine by running the following in PowerShell.

Enable-PSRemoting –force

Now place the PowerShell script you want to execute on a location on your local machine.

Now we can run the following PowerShell command to execute the script on the remote machine Smile (Edit the below highlighted in red to match the remote machine name and the PowerShell file location)

Invoke-Command -ComputerName machinename -FilePath C:FileLocationfilename.ps1

Categories: Uncategorized Tags: ,

Exchange PowerShell command to show permissions on a particular or all users mailboxes

April 28th, 2011 Daniel Davies Comments off

We had a request recently to list what users have rights to a specific users mailbox.

This can easily be done using the following command.

Get-MailboxPermission –Identity “UserName” | fl user, accessrights

This gives an output like below.

image

If you would like to see permissions for every users mailbox run the following command

Get-MailboxPermission -Identity * | fl user, accessrights , identity > C:Perms.txt
(You can change the file location to wherever you would like)

The list of the Users and Permissions will all be in the Perms.txt file.