Thursday, 27 November 2014

File cannot be loaded because the execution of scripts is disabled on this system

There two to solve this error :

  • Set policy
  • By pass the policy
  1. Set policy
Set-ExecutionPolicy Unrestricted
or
Set-ExecutionPolicy RemoteSigned

     2. By pass the policy

powershell.exe -ExecutionPolicy ByPass -File script.ps1

Get Bulk Server IPS

  • List all server in sheet and save it by name "InputServerIPs.csv". And name column by name "ServerIPs".
example:
ServerIPs
server1
server2
.
.
.
server


  • Copy below code and paste in notepad and save by name GetServerIPs.ps1
  • Call the script according to environment. ex:
  • .\GetServerIPs.ps1 -env env1,
  • .\GetServerIPs.ps1 -env env2,
  • .\GetServerIPs.ps1 -env production
  • Get output in "OutputServerIPs.csv" in location where your "InputServerIPs.csv" is located.




param
(
[Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [System.String] $env
)
$data = Get-Content "C:\Users\sp_farm\InputServerIPs.csv"
$startDate =Get-Date
Write-host $startDate -ForegroundColor Red
$env1Domain = ".env1.net"
$env2Domain = ".env2.net"
$productionDomain = ".production.net"
if($env -eq "env1")
{
foreach($item in $data)
{
if($item -ne "ServerIPs")
{
try
{
$item
$server = $item + $env1Domain
$serverIP = ping $server
$getServerIP =$serverIP.GetValue(2)
$SpiltbyColon =$getServerIP.Split(":")
$splitbyfrom = $SpiltbyColon[0].Split("m")
$result = $item + ":" + $splitbyfrom[1]
}
catch
{
 $result = $item + ":" + "Not Found"
}
Write-Host $result -ForegroundColor Blue
write-output $result >> "C:\Users\sp_farm\OutputServerIPs.csv"
}
}
}
elseif($env -eq "env2")
{
foreach($item in $data)
{
if($item -ne "ServerIPs")
{
try
{
$item
$server = $item + $env2Domain
$serverIP = ping $server
$getServerIP =$serverIP.GetValue(2)
$SpiltbyColon =$getServerIP.Split(":")
$splitbyfrom = $SpiltbyColon[0].Split("m")
$result = $item + ":" + $splitbyfrom[1]
}
catch
{
 $result = $item + ":" + "Not Found"
}
Write-Host $result -ForegroundColor Blue
write-output $result >> "C:\Users\sp_farm\OutputServerIPs.csv"
}
}
}
else
{
foreach($item in $data)
{
if($item -ne "ServerIPs")
{
try
{
$item
$server = $item + $productionDomain
$serverIP = ping $server
$getServerIP =$serverIP.GetValue(2)
$SpiltbyColon =$getServerIP.Split(":")
$splitbyfrom = $SpiltbyColon[0].Split("m")
$result = $item + ":" + $splitbyfrom[1]
}
catch
{
 $result = $item + ":" + "Not Found"
}
Write-Host $result -ForegroundColor Blue
write-output $result >> "C:\Users\sp_farm\OutputServerIPs.csv"
}
}
}
$endDate = Get-Date
Write-host $endDate -ForegroundColor Green

Wednesday, 26 November 2014

Get time zone + window application

Create two label in form by name ISTTime and CSTTime which show time in IST and CST


{
TimeZone zone = TimeZone.CurrentTimeZone;


 DateTime local = zone.TolocalTime(DateTime.Now);


#get time zone information

TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");


#get offset of the zone information


TimeSpan offset = tzi.GetUtcOffset(DateTime.UtcNow);


#Add offset to universal time
DateTime testDateTime = DateTime.UtcNow.Add(offset);


#display local and universal time in label
ISTTime.Text =local.ToString();


CSTTime.Text=testDateTime.ToString();
}

Tuesday, 25 November 2014

GetFileName + powershell

#get filename in $data variable
$data = get-content "directory:\Filepath\Filename"


#iterate the collection one by one and assign item variable
foreach($item in $data)
{
#get filename in filename variable
   $Filename = [System.IO.Path]::GetFileName($item)


#write output in output file
  write-output >> directory:\Filepath\output.csv
}

Thursday, 20 November 2014

Trust SSL + ServicePointManager.ServerCertificateValidationCallback Property

Trust SSL + ServicePointManager.ServerCertificateValidationCallback Property


Gets or sets the callback to validate a server certificate


An application can set the ServerCertificateValidationCallback property to a method to use for custom validation by the client of the server certificate. When doing custom validation, the sender parameter passed to the RemoteCertificateValidationCallback can be a host string name or an object derived from WebRequest (HttpWebRequest, for example) depending on the CertificatePolicy property.
When custom validation is not used, the certificate name is compared with host name used to create the request. For example, if Create(String) was passed a parameter of "https://www.contoso.com/default.hmtl", the default behavior is for the client to check the certificate against www.contoso.com.




Powershell Script:




$data = get-content InputLogs.csv
foreach($item in $data)
{
try
{
$Filename = [System.IO.Path]::GetFileName($item)


$tofile   = "D:\DownloadFiles\" + $Filename


$webclient = New-Object System.Net.WebClient

[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}


$webclient.UseDefaultCredentials = $true


$webclient.DownloadFile($item, $tofile)
}
catch
{
write-output "$item" >> LogsExceptionCSV.csv

Write-Host Exception at $item and File not found
}
}


reference blogs:
https://social.technet.microsoft.com/Forums/windowsserver/en-US/a260da46-b035-478c-9887-ba5a0a4777a0/powershell-10-trust-any-ssl-cert


http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.servercertificatevalidationcallback(v=vs.110).aspx

Tuesday, 18 November 2014

Datasheet view + multilune text box of type enhance rich text box + SharePoint

Data sheet view with multiline text box column of  type enhanced do not allow you to edit item in datasheet view.


In standard view you are able edit item.


Multiline text box are of three types in SharePoint
  1. Plain
  2. Rich
  3. Enhanced


If you selected multiline text box of first two type then you are able to edit the item in datasheet view.
But if you are going with 3 option ENHANCED then it wont allow you to edit item in datasheet view.


Enhanced multiline text box is read only in Datasheet view.


Its an limitation with SharePoint Out of box features.

Monday, 17 November 2014

BCS SHAREPOINT 2013


                                                              BCS SHAREPOINT 2013

We’re often asked about what SharePoint’s Business Connectivity Service (BCS) in SharePoint 2010 and 2013  can be used for and how difficult it is to set up. While the short answer is pretty simple – BCS enables you to connect to ‘other’ data sources outside of SharePoint and literally treat them as a SharePoint List. For those that worked with the “Business Data Catalog” (BDC) in SharePoint 2007, be aware that BCS’s core is the BDC but with a significant change – instead of a one-way ‘view’ that was available in 2007, 2010/2013 feature ‘operations’ that provide two way usage (read, write, update, delete, etc.).
On a whiteboard it can be pretty easy to explain how to use it but it can be confusing since it requires setup in SQL Server, Central Administration and SharePoint Designer. For more advanced operations it can also include Visual Studio. That’s a lot of moving parts for some folks.
Since we provide a number of customized training programs, during the course of this we’ve created a simple step by step tutorial that has helped many of our clients and students get up to speed quickly. Not overly complex, the tutorial covers creating an external data source, creating an external content type and generating the list to use in a SharePoint site. To keep it simple, no coding of any kind is required.
In addition to the tutorial, we’ve also provided fixes for some of the most common issues and a list of some very useful links to dig into BCS further.

Services that allows integration of data which live outside the SharePoint in to the SharePoint and office products.
Data can be easily update and viewed on the remote systems and data can be easily integrated with authoritative sources.
Centralized infrastructure for managing connections to external sources.
Common interface for accessing data through out SharePoint.
Indexing data in eternal systems for searching on through SharePoint.
 



Here the steps for creating it: Data Source is SQL SERVER
Create a table/view from which you want to fetch data:

  • I created two table Customer and CustomerAddress above that I created view by name CustomerDetails.
  •  Create new External content types in SharePoint Designer
    • Name the external content type
      • Choose external systems
        • Add connection
          •  Select data source type
            • As you added the source with its name then all its objects get exposed to it.
            • As I added BCS Database to it then all object of BSC Database gets exposed to it.
              • Select the object on which CURD operation have to apply.
              • I choose Customer Details  
              • Map the identifie
              • Finish & save. Now External List is ready to use in SharePoint 2010/2013
              • Open CA
              • Open Business Data Connectivity Service
              • Here you get External list (new)
              • Set Object permission for it and then it will to perform CRUD operations. 
              • Create Eterna l List
              • Add the External Content Type and name it.
              • Open the list and get result which is similar to Database results.


 


 

NOTE:Please follow link for detailed information of BCS
Click Here ==>> Step by Step configuration of BCS in SharePoint 
https://code.msdn.microsoft.com/BCS-SHAREPOINT-20102013-63918778
Step by Step configuration of BCS Services in SharePoint 2010/2013
 Using BCS you can perform forward and backward data manipulation. But by using BDC you can perform only forward data manipulations.

Connectors Types:

SQL SERVER

WCF

.NET Managed Code

Custom