Tuesday, 27 October 2015

Powershell deleting SharePoint and SQL 90 days old logs files




#---------------------------------------------------------------#
#Script Ttile : deleting SharePoint and SQL 90 days old logs files 
#Scrit Author : KRR 
#---------------------------------------------------------------#

$SPLogs = "C:\logs"  # SharePoint log file location

$SqlLogs = "C:\Sql_logs" #SQL Server Log file location

$path = @($SPLogs,$SqlLogs)
$limit = (Get-Date).AddDays(-90)  #log file age
foreach($logs in $path)
{
write-host "SharePoint and SQL  logs are deleting!!!!" -ForegroundColor Yellow -BackgroundColor Black

Get-ChildItem $logs -Recurse |where-object{$_.CreationTime -gt $limit} | Remove-Item

write-host "SharePoint and Sql logs deleted sucessfully" -ForegroundColor green -BackgroundColor Black

}

Powershell Script to delete 90 days old SharePoint ULS logs


#---------------------------------------------------------------#
#Script Ttile : deleting the 90 days old log files from one server
# Scrit Author : KRR 
#---------------------------------------------------------------#

$SPLogs = "C:\logs"  # SharePoint log file location
$limit = (Get-Date).AddDays(-90)  #log file age
try
{
write-host "SharePoint ULS logs are deleting!!!!" -ForegroundColor Yellow -BackgroundColor Black

Get-ChildItem $SPLogs -Recurse |where-object{$_.CreationTime -lt $limit} | Remove-Item

write-host "SharePoint ULS logs deleted sucessfully" -ForegroundColor green -BackgroundColor Black
}
catch
{
write-error "error deleting the log files or no files found" 
}

#

Thursday, 8 October 2015

Powershell to Enable Remote Desktop Remotely


Below are the Powershell cmdlets to enable Remote Desk top feature on Servers and Client OS.

Enable Remote Desktop:

Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server'-name "fDenyTSConnections" -Value 0



Disable Remote Desktop:

Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server'-name "fDenyTSConnections" -Value 1



Enable secure RDP authentication:


Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -name "UserAuthentication" -Value 1


Allow incoming RDP on firewall:

Enable-NetFirewallRule -DisplayGroup "Remote Desktop"

Wednesday, 7 October 2015

Install and Configure Active Directory and DNS with PowerShell


I have created this script to install and Configure Active Directory services & DNS

Please save below script as "Install_Configure_AD_DNS.Ps1" file and execute in Powershell with Administrator rights on Server.

References : 
https://technet.microsoft.com/en-us/library/hh974720(v=wps.630).aspx



#----------------------------------------------------------------------------#
#Script Title : Install and Configure Active Directory and DNS
#Script Author : KRR
#----------------------------------------------------------------------------#
Import-Module ServerManager
Write-Host "Installing the windows feature: Active Directory Domain Service" -ForegroundColor "Green"
Install-windowsfeature AD-domain-services  –IncludeManagementTools
Write-Host "Active Directory Domain Service Installed successfully!!!" -ForegroundColor "Green"
Write-Host "Importing Active Directory Module..........." -ForegroundColor "Yellow"
Import-Module ADDSDeployment
Write-Host "Importing Active Directory Module Done" -ForegroundColor "Green"
#----------------------------------------------------------------------------------------#
Write-Host "Please enter the below details to configure AD and DNS" -ForegroundColor "Blue"
#-----------------------------------------------------------------------------------------#
$DomainandForestModes = @("-- Windows Server 2003: 2 or Win2003","-- Windows Server 2008: 3 or Win2008","-- Windows Server 2008 R2: 4 or Win2008R2","-- Windows Server 2012: 5 or Win2012","-- Windows Server 2012 R2: 6 or Win2012R")
#------------------------------------------------------------------------------------------#
Write-Host "Below are the domain and Forest function levels..." -ForegroundColor "Yellow"
$DomainandForestModes
$domainMode = Read-Host "Please enter Domain Functional Mode number or Value"
$ForestMode = Read-Host "Please enter Forest Functional Level"
$InstallDNS = Read-Host "Please enter '$true' if you want install DNS"
$DomainName = Read-Host "Please enter Domain Name , Example : corp.com"
$DomainNetbiosName = Read-Host "Please enter Domain NetBios Name , Example : corp"
#------------------------------------------------------------------------------------------#
Write-Host " Active Directory  and DNS configuration is in-progress" -ForegroundColor "Green"
Install-ADDSForest  -CreateDnsDelegation:$false -DatabasePath "C:\Windows\NTDS" -DomainMode $domainMode -DomainName $DomainName -DomainNetbiosName $DomainNetbiosName -ForestMode $ForestMode -InstallDns:$InstallDNS -LogPath "C:\Windows\NTDS" -NoRebootOnCompletion:$false -SysvolPath "C:\Windows\SYSVOL" -Force:$true
#-----------------------------------------------------------------------------------------------#
Write-Host "Active Directory and DNS configuration Completed!" -ForegroundColor "Green"

#--------------------------------End-----------------------------------------------------------#

Please feel to add comments and suggestions

Thanks
KRR