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’

Run PowerShell Script Remotely

June 2nd, 2011 Daniel Davies No comments

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:\FileLocation\filename.ps1

Categories: Uncategorized Tags: ,

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

April 28th, 2011 Daniel Davies No comments

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.

Do not prompt when writing to output file in DPM PowerShell

April 14th, 2011 paulw 2 comments

Just a quick one for anyone else that uses a DPM PowerShell command to output to a file and keeps getting prompted to perform the action:

image

If you are writing anything that has a for each clause in there then you can end up typing “Y” for each time it wants to write to the file.

All you need to do is add in the following option at the end of your line:

-confirm:$false

So the example command from above would read:

“What you want to output” | out-file “c:\outputfile.txt” -confirm:$false

The file should then overwrite without prompting.

Paul

Categories: Uncategorized Tags: ,

Service Manager PowerShell Script to close resolved cased after 2 days of inactivity

March 11th, 2011 Daniel Davies No comments

Just a quick PowerShell script which will close any case that have been Inactive for 2 days and are currently in a resolved state in Service Manager.

CMDLets from “http://smlets.codeplex.com/

Import-Module SMLets
Get-SCSMIncident -Status resolved -InactiveFor 2.00:00:00 | Set-SCSMIncident -Status Closed -Comment “Comment Here” 

Delete IIS logs after certain number of days via PowerShell

February 17th, 2011 Daniel Davies No comments

Just a quick script that may come in useful to you. The below Powershell script will delete IIS Log files older than 7 days that are in the “C:\inetpub\logs\LogFiles\w3svc1” directory. You can alter the script to how many days old the log files can be and also your IIS log location (Highlighted in red).

get-childitem -Path C:\inetpub\logs\LogFiles\w3svc1 -recurse | where-object {$_.lastwritetime -lt (get-date).addDays(-7)} | Foreach-Object { del $_.FullName }

Categories: Uncategorized Tags: ,

Bulk Mailbox Moves Exchange 2010

February 2nd, 2010 Daniel Davies 4 comments

You may come across an issue where you need to Migrate Multiple Mailboxes in bulk, we’ve created a Exchange Powershell script which will move all users into there targeted mail stores.

Instructions

Before we run this powershell script  we need to create a csv file with the users display name and there targeted exchange database, to do this see below.

1, open notepad.exe

2, now write the following text on your first line in notepad “user,database” (without quotation marks)

3, Go to the next line and then type a users name  first and then add a comma and finally type the desired store.

4, You should end up with a list like below with all the users you want to import

user,Database
Jovan Davis,Store 3
Daniel Davies,Store 2
Hardeep Bains,Store 1

5, Finally save the file as a csv file and name it “MM.csv” in the following directory “C:\MailboxMove””

6, Now open notepad again and copy all the below text into it. Finally save this as a PS1 file and run this via the Exchange management Shell.
_________________________________________________________________________

$Userstodatabase = import-csv C:\MailboxMove\MM.csv
foreach ($Record in $Userstodatabase)
{
$users = $record.user
$database = $record.database
New-MoveRequest –identity $users –TargetDatabase “$Database”
}

____________________________________________________________________________

This will now move the mailboxes :)

If you want to check the status if the moves simply copy the below script into a PS1 file and run it from the exchange shell and it will list the progress of all users mailboxes specified in the CSV.

____________________________________________________________________________

$Userstodatabase = import-csv C:\MailboxMove\MM.csv
foreach ($Record in $Userstodatabase)
{
$users = $record.user
Get-MoveRequest –identity $users
}

___________________________________________________________________________ 

Hope this helps :)

Daniel Davies