Category Archives: Uncategorized

Execute SharePoint timer jobs on multiple computers

Published / by / Leave a Comment

The Invoke-Command cmdlet runs commands on a local or remote computer and returns all output from the commands, including errors. By using a single Invoke-Command command, you can run commands on multiple computers.

To run a single command on a remote computer, use the ComputerName parameter. To run a series of related commands that share data, use the New-PSSession cmdlet to create a PSSession (a persistent connection) on the remote computer, and then use the Session parameter of Invoke-Command to run the command in the PSSession. To run a command in a disconnected session, use the InDisconnectedSession parameter. To run a command in a background job, use the AsJob parameter.

invoke-command -computername computer1,computer2 {asnp *sharepoint*;stop-service spadminv4; Start-SPAdminJob;start-service spadminv4}

This command stops the admin service, executes the timer jobs and starts the admin service.


SharePoint – Render HTML files in the browser

Published / by / Leave a Comment

SharePoint 2013 web applications have browser handling level set to strict. This setting prevents browser from rendering HTML files. HTML files are one example file type that you may want to have open directly in the browser rather downloading and then opening. Use the below script to add HTML and HTM Mime types to Web Application.

$webApplication = Get-SPWebApplication "http:/contoso"
//HTML Files 
//HTM Files

AWS Lambda Function for Snapshots

Published / by / Leave a Comment

You can back up the data on your EBS volumes to Amazon S3 by taking point-in-time snapshots. Lambda function can be used to automate this for daily or weekly backups. Using Lambda is best option than running a machine with Bash or PowerShell scripts. This function also deletes the snapshots that are 30 days or old.

import boto3
 import collections
 import datetime
 import logging
 logger = logging.getLogger()
#Retention for 30 days - Change accordingly
retention_days = 30
def _getRegions():'Getting list of regions')
 ec2Client = boto3.client('ec2')
 regions = []
 for region in ec2Client.describe_regions().get('Regions', []):
 return regions
 except Exception as e:
 raise e
 def lambda_handler(event, context):
count = 0
 regions = _getRegions()
 for region in regions:'RegionName', ''))
 ec = boto3.client('ec2',region_name=region.get('RegionName', ''))
 reservations = ec.describe_instances()['Reservations']
 for reservation in reservations:
 for instance in reservation['Instances']:
 count = count + 1
 # retention_days = [int(t.get('Value')) for t in instance['Tags'] if t['Key'] == 'Retention'][0]
 # retention_days = 14
 instance_name = [str(t.get('Value')) for t in instance['Tags'] if t['Key'] == 'Name'][0]
 #logger.error("Name not defined for " + instance['InstanceId'])
 instance_name = str(instance['InstanceId'])
for dev in instance['BlockDeviceMappings']:
 if dev.get('Ebs', None) is None:
 vol_id = dev['Ebs']['VolumeId'] + '-' + str(dev['DeviceName']) + '-' +"%Y-%m-%d-%H:%M"))'Found EBS volume %s on instance %s' % (vol_id, instance['InstanceId'])
 snap = ec.create_snapshot(VolumeId=vol_id,)
 value = instance_name + '-' + str(dev['DeviceName']) + '-' + datetime.datetime.utcnow().strftime("%Y:%m:%d:%H:%M")
 ec.create_tags(Resources=[snap['SnapshotId'],],Tags=[{'Key': 'Name', 'Value': value },])
 delete_date = datetime.datetime.utcnow() - datetime.timedelta(days=retention_days)
 delete_date = delete_date.strftime('%Y-%m-%dT%H:%M:%S.000Z')'Deleting snapshots older than %d days (before %s) in region %s' % (retention_days, delete_date, regionname) )'setting date to delete:' + str(delete_date))
 snapshotsobject = ec.describe_snapshots(OwnerIds=['XXXXXXXXXXX'])
 snapshots = snapshotsobject['Snapshots']
 for snapshot in snapshots:
 start_date = snapshot['StartTime'].strftime('%Y-%m-%dT%H:%M:%S.000Z')
 if start_date < delete_date:
 try:'Deleting snapshot: snapshotid-' + snapshot['SnapshotId'] +' createddate-'+str(snapshot['StartTime'] ))
 logger.error('error deleting snapshot: snapshotid-' + snapshot['SnapshotId'] +' createddate-'+str(snapshot['StartTime'] ))
return 'success'

Your Intranet in Your Pocket: The SharePoint mobile app

Published / by / Leave a Comment

Microsoft launched SharePoint for iOS, its first mobile SharePoint app. The tool gives you access to the files, portals, sites and teams that you’re used to on the desktop. It’s also smart enough to hop between apps depending on what you’re accessing. It’ll jump to OneDrive if you’re peeking at the company’s document library, for instance, or switch to one of the Office apps if you’re opening a recent file.

Amazon Web Service (AWS): Script to add Windows Machine to Domain (devops)

Published / by / Leave a Comment

When you launch an instance in Amazon EC2, you have the option of passing user data to the instance that can be used to perform common automated configuration tasks and even run scripts after the instance starts. You can pass two types of user data to Amazon EC2. The below script can be used to add these servers to domain automatically.

Set-ExecutionPolicy -executionpolicy unrestricted -Force -verbose
$user = "contoso\_sys_joincomputer"
$pass = "********" | ConvertTo-SecureString -AsPlainText -Force
$DomainCred = New-Object -TypeName System.Management.Automation.PSCredential ($user, $pass)
Add-Computer -NewName COMPUTERNAME -DomainName -Credential $DomainCred -Restart