Monday 22 December 2014

A quick script to do an IISRESET on Multiple server.
  1. [array]$servers = "MyServer1","MyServer2","MyServer3","MyServer4"  
  2. foreach ($server in $servers)  
  3. {  
  4.    Write-Host "Restarting IIS on server $server..."  
  5.    IISRESET $server /noforce  
  6.    Write-Host "IIS status for server $server"  
  7.    IISRESET $server /status  
  8. }  
Write-Host IIS has been restarted on all servers.


In my current project requirement, we have to add query suggestions to sharepoint 2013 Search. Here is the powershell script thats been used to upload the query suggestion and kickstart the timer job as well.
  1. $Service = Get-SPEnterpriseSearchServiceApplicationProxy  
  2. $web = Get-SPWeb -Identity http://mysite/Test  
  3. $owner = Get-SPEnterpriseSearchOwner -Level SPWeb -SPWeb $web  
  4. $Fedmanager = New-Object Microsoft.Office.Server.Search.Administration.Query.FederationManager –ArgumentList $Service  
  5. $source = $Fedmanager.GetSourceByName("Local SharePoint Results", $owner)  
  6. Import-SPEnterpriseSearchPopularQueries -SearchApplicationProxy $Service -Filename C:\query.txt -ResultSource $source -Web $web  
  7. $timerjob = Get-SPTimerJob -type "Microsoft.Office.Server.Search.Administration.PrepareQuerySuggestionsJobDefinition"  
  8. $timerjob.RunNow()  

  1. <script src="/Style Library/scripts/jquery-1.10.1.min.js"></script>  
  2. <script type="text/javascript">  
  3. $(document).ready(function () {   
  4.   
  5.   
  6. var currentUser;  
  7. // Ensure that the SP.js is loaded  
  8. if (SP.ClientContext != null) {  
  9.   SP.SOD.executeOrDelayUntilScriptLoaded(getCurrentUser, 'SP.js');  
  10. }  
  11. else
  12. {  
  13.   SP.SOD.executeFunc('sp.js'null, getCurrentUser);  
  14. }  
  15.    
  16. function getCurrentUser() 
  17. {  
  18.    context = new SP.ClientContext.get_current();  
  19.     web = context.get_web();  
  20.   currentUser = web.get_currentUser();  
  21.   context.load(currentUser);  
  22.   context.executeQueryAsync(onSuccessMethod, onRequestFail);  
  23. }  
  24.   
  25. function onSuccessMethod(sender, args) {  
  26.   var account = currentUser.get_loginName();  
  27.     
  28.   var title = currentUser.get_title();  
  29.    
  30.   currentUserAccount = account.substring(account.indexOf("|") + 1);  
  31.     
  32. }  
  33.   
  34. // This function runs if the executeQueryAsync call fails.  
  35. function onRequestFail(sender, args) {  
  36.  // alert('request failed' + args.get_message() + '\n' + args.get_stackTrace());  
  37. }  
  38.   
  39.   
  40. });  
  41. </script>  

No comments:

Post a Comment