Uncategorized

Created a R/RW/L SG for root folders in a share

$folders = get-childitem -directory -path "\\Server\share"



ForEach ($name in $folders)
{

$ns = $name.name -replace ' ','.'
#write-host "Grant Read/Write access to '$($name.FullName)' This is a SN Group only"
#Write-host "sg.ag.$($ns).RW"

#Read/Write Groups
#New-ADGroup -server "ral1-dc01" -DisplayName "sg.ag.$($ns).RW" -Name "sg.ag.$($ns).RW"  -Description "Grant Read/Write access to '$($name.FullName)' This is a SN Group only" -GroupScope Universal -Path "OU=ServiceNow,OU=File Groups,OU=Security Groups,DC=trialcard,DC=com"

#Read Groups
New-ADGroup -server "ral1-dc01" -DisplayName "sg.ag.$($ns).R" -Name "sg.ag.$($ns).R"  -Description "Grant Read Only access to '$($name.FullName)' This is a SN Group only" -GroupScope Universal -Path "OU=ServiceNow,OU=File Groups,OU=Security Groups,DC=trialcard,DC=com"

#List Groups
New-ADGroup -server "ral1-dc01" -DisplayName "sg.ag.$($ns).L" -Name "sg.ag.$($ns).L"  -Description "Grant List access to '$($name.FullName)' This is a SN Group only" -GroupScope Universal -Path "OU=ServiceNow,OU=File Groups,OU=Security Groups,DC=trialcard,DC=com"

First start by forcing the creation of your PowerShell ISE profile file if it doesn’t exist

if (!(Test-Path -Path $PROFILE ))&amp;lt;br&amp;gt;&lt;br&gt;<br>
{ New-Item -Type File -Path $PROFILE -Force }

Second, within your ISE console, type the following

psEdit $profile

In the script pane, just copy/paste the below blue script

$StopWatch = [System.Diagnostics.StopWatch]::StartNew()

Function Test-Command ($Command)

{

Try

{

Get-command $command -ErrorAction Stop

Return $True

}

Catch [System.SystemException]

{

Return $False

}

}


IF (Test-Command "Get-Mailbox") {Write-Host "Exchange cmdlets already present"}

Else {

$CallEMS = ". '$env:ExchangeInstallPath\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto -ClientApplication:ManagementShell "

Invoke-Expression $CallEMS


$stopwatch.Stop()
$msg = "`n`nThe script took $([math]::round($($StopWatch.Elapsed.TotalSeconds),2)) seconds to execute..."
Write-Host $msg
$msg = $null
$StopWatch = $null

}
#Add Exchange snapin if not already loadedif (!(Get-PSSnapin | where {$_.Name -eq "Microsoft.Exchange.Management.PowerShell.E2010"}))

{

Write-Verbose "Loading the Exchange snapin"

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

. $env:ExchangeInstallPath\bin\RemoteExchange.ps1

Connect-ExchangeServer -auto -AllowClobber

}
script by Paul Cunnigham.
Removes spam from exchange 2010 with powershell. Creates a log file in G:\s\Logs\exchange\  Edit the $spam var. Use “from:$spam” for From and “subject:$spam” for Subject.  
$spam = "pravinchauhan1991@yahoo.in"

$today = (get-date).tostring("MM-dd-yyyy")

$ExDBs = "db04","db08","db12","db16","db20","db24","db28"
Foreach($ExDB in $ExDBs)
{

#Defines source and destination
$outfile = 'G:\s\Logs\exchange\SpamCleanUp_' + $today + '_' + $spam + '_' + $ExDB + '.txt'
Get-mailbox -database $ExDB -resultsize unlimited | search-mailbox –searchquery “from:$spam” -LogLevel Full -TargetMailbox discovery -TargetFolder inbox -DeleteContent -force | ft displayname, resultitemscount, resultitemssize >> "$outfile"
}