Monday, 23 June 2014

Remote Powershell



Use remote powershell if you dont have installed Exchange Management tool.

Use the below script to log in through remote powershell

$username = 'domain\username'
$password = '**************'
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList @($username,(ConvertTo-SecureString -String $password -AsPlainText -Force))

$session = New-PSSession -Authentication basic -Credential $cred -ConnectionUri https://*****.******.com/PowerShell -ConfigurationName Microsoft.Exchange
Import-PSSession $session

If you want to login to the different machine through remote use the below code

$cred=Get-Credential
$session = New-PSSession -Credential $cred -ComputerName <remote machine>
Enter-PSSession $sessio

To exit the remote session

Exit-PSSession
Remove-PSSession $session

Powershell Execution policy

if the powershell scripts to be allowed to run the scripts on your computer, Use the below execution policy cmdlets

Set-ExecutionPolicy RemoteSigned

Then use the below cmdlet to check the execution policy

Get-ExecutionPolicy




Friday, 9 May 2014

Convert Powershell Script as Executable File

How to convert the Powershell Script as Executable File?

Sometimes we need to run the PS script as an executable file. In this case we could convert the powershell script as an exe file. Then run it on the windows OS. Please pay the attention on the Microsoft .Net Framework while creating the executable file.

1. Install the latest version of PowerGUI Script Editor

2. Write the script on the PowerGUI Script Editor which you want to convert it as EXE file

3. Then Click on "Tools"

4. Then Click on "Compile Script"

5. If you want you can show powershell script on console. Else you could disable that option


Wednesday, 22 January 2014

Disk Usage Information

Program to get Disk usage information 

Use the below script to find the disk usage on windows. This script would be helpful when you want to work on disk utilization tasks such as cleanup process on  disks, Auditing purpose etc,.

Use this script to check the limit of disk utilization. And use Send-Mailmessage to send the alert to the specific person and schedule the script on task scheduler.

function get-DiskUsage {

Get-ChildItem -Recurse -Directory | Select-Object FullName,
@{ Name="Size";
Expression={ ($_ | Get-ChildItem |
Measure-Object -Sum Length).Sum + 0 } }
}

Thursday, 9 January 2014

Make your Computer to speak with Powershell

Use the COM object to make the computer to speak. We could intimate the administrator using this computer speaking feature using powershell when they receive an error. This would be helpful to the scripting developer.

Use the New-Object cmdlet to create the COM object as mentioned in the below screenshot.




.Net Static Method

How to list the static method using Get-Member cmdlet?

Once you know the .net type, we can list the static method using the Get-Member.

[System.Guid]::Newguid()

[Sytem.Guid] -> .Net Type

Newguid() -> .Net Method

Have look at the below screenshot.



If you are in a situation to fetch the local machine timezone, you can use the method as mentioned in the below screenshot.

Wednesday, 13 February 2013

Deleting the Meeting Requests Made by terminated users from all the roommailboxes


Run this script on Exchange server 2010. You could delete the meetings made by terminated users from all the room mailboxes. Ensure that you are running this script only for terminated users. Else script will not run.

Give the required input while running this script.



[void][System.reflection.assembly]::LoadWithPartialName('microsoft.visualbasic')

$recipient=[Microsoft.visualbasic.interaction]::inputbox("Enter the Recipient Name to delete the Meeting requests from all the room mailoxes","name","Sankar_M")


$mailid=[Microsoft.visualbasic.interaction]::inputbox(" Enter your mail id to create a foler called REPORT in your outlook in which you can find the deleted contents","name","Sankar@Domain.com")

if(get-recipient $recipient -warningaction:silentlycontinue)
{
[Microsoft.visualbasic.interaction]::msgbox("Recipient is Existing in Production. Ensure that You are running this program for Terminated User")

Write-host "Recipient is Existing in Production. Ensure that You are running this program for Terminated User"

break
}
else
{

[Microsoft.visualbasic.interaction]::msgbox("Hello, Please Wait Until the Program completes")

Write-Progress -Activity "Preparing" -Status "Retrieving Roommailbox list" -PercentComplete 0
$rooms=get-mailbox -recipienttypedetails roommailbox -resultsize unlimited -warningaction:silentlycontinue| where {$_.name -notlike "*test*"}

$count=$rooms.count




foreach($room in $rooms)

{

$i=$i+1
$percentage=$i/$count*100


Write-Progress -Activity "Collecting mailbox details" -Status "Processing mailbox $i of $Count - $room" -PercentComplete $percentage


$room | search-mailbox -searchquery "kind:meetings from:$recipient" -targetmailbox $mailid -targetfolder "REPORT" -deletecontent -force
}}

Friday, 7 December 2012

Powershell Help

To get help in Graphical window

C:\> help Get-EventLog -showwindow