PowerShell to get all users group and objects from Active Directory

Get every object and property:

Get-ADUser -Filter * -Properties *| select * | Export-CSV "C:\PS_Every_Object.csv"

^ Depending on the number of user this could take a few minutes to run. This is also handy to hunt for properties.

This will export userId, email, employee Id, and company name.

Get-ADUser -Filter * -Properties SamAccountName,EmailAddress,EmployeeID,Company | select SamAccountName,EmailAddress,EmployeeID,Company | Export-CSV "C:\Email_Addresses.csv"

SOLVED: Exception calling “StartWorkflow” with “X” argument(s)

Trying to start a SharePoint workflow using PowerShell and I couldn’t get past this error:

Exception calling “StartWorkflow” with “4” argument(s): “Object reference not set to an instance of an object.”

or

Exception calling “StartWorkflow” with “3” argument(s): “Object reference not set to an instance of an object.”

 

NO clue if there is a bug in my farm, but the script below works.  Ended up having to re-get the item when running the workflow. $manager.StartWorkflow($list.GetItemById($item.ID),$assoc,$data,$true)

$web = Get-SPWeb "http://rootSiteCollection.com"
$list = $web.Lists["Shared Documents"]

$assoc = $list.WorkFlowAssociations |Where { $_.Name -eq "tacoWF"}
$data = $assoc.AssociationData
$manager = $web.Site.WorkflowManager

$sQuery = New-Object Microsoft.SharePoint.SPQuery 

#Get all items with an ID greater than 5 
$caml = '<Where><Gt><FieldRef Name="ID" /><Value Type="Counter">5</Value></Gt></Where>'
$sQuery.Query = $caml
$fItems = $list.GetItems($sQuery)

Foreach($item in $fItems)
{
	$manager.StartWorkflow($list.GetItemById($item.ID),$assoc,$data,$true)
}

 

SharePoint OfficialFile.asmx NotFound

When using the SubmitFile method of the OfficialFile.asmx service, I was returned this value: NotFound

NotFound

Simple fix was to add my account to the Records Center Web Service Submitters group on the site.

Healthy return message from the service:
“Successhttp://site/_layouts/DocIdRedir.aspx?ID=AHVCF7U4ZST3-8-55&hintUrl=myLibTestA%2ftest1_2F4IOO.docx”

Good example on how to upload load files to the Drop Off Library using OfficialFile.asmx service.
https://msdn.microsoft.com/en-us/library/office/gg650433(v=office.14).aspx

The post outlines setting up routing rules and submitting files.

More info on the web service can be found here:
http://download.microsoft.com/download/8/5/8/858F2155-D48D-4C68-9205-29460FD7698F/[MS-OFFICIALFILE].pdf

Value                                                   Meaning
Success                                                    The operation is successful.
MoreInformation                                  The operation is successful but further action is needed.
InvalidRouterConfiguration               The operation failed because the repository was not configured for routing.
InvalidArgument                                   The operation failed because of an invalid argument.
InvalidUser                                             The operation failed because of an invalid user.
NotFound                                                The operation failed because the user was not authorized to submit files.
FileRejected                                            The operation failed because of a rejected file.
UnknownError                                       The operation failed because of an unknown error.

SharePoint 2016 new-spconfigurationdatabase the user does not exist

When installing SharePoint 2016 from PowerShell, make sure you use the machineName\userName when prompted.

 

Example:

New-SPConfigurationDatabase –DatabaseName SharePoint_Config –DatabaseServer machineName\sqlInstance –AdministrationContentDatabaseName SharePoint_Content –Passphrase (ConvertTo-SecureString BigTaco@12345 –AsPlaintext –Force) –FarmCredentials (Get-Credential) -localserverrole SingleServerFarm

A login prompt will appear.

for the username: enter your machine name \ username (WIN-SP16\spUser).

Error I received when I tried to use spUser without the machine name.

new-spconfigurationdatabase the user does not exist

Are SharePoint Designer Workflows Using Custom Features or Solutions (iLoveSharePoint)

Needed to audit a farm to see if a CodePlex solution was being used in SharePoint Designer workflows.  In my case, I needed to see where the iLove SharePoint  solution was being used. The script below is only targeted at one web and is looking for word “ILoveSharePoint” in the XML.

 


if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) 
{
	Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}

[Microsoft.SharePoint.SPSecurity]::RunWithElevatedPrivileges(
	{

		$resultsarray =@()
		#output file name
		$fileName = "C:\ilsp-" + $(Get-Date -Format "yyyyMMddHHmmss") + ".csv"
		#name of the feature we are looking for
		$wFeatureName = "ILoveSharePoint"

		Function GetFiles($folder)
 { 
			foreach($file in $folder.Files)
			{
				if($file.Name.Split('.')[-1] -eq "xoml")
				{
					$web2 = Get-SPWeb $file.Web.Url
					$wFile = $web2.GetFileOrFolderObject($web2.URL +"/"+ $file.URL)

					if ($wFile.Exists -eq "True")
					{
						$wXml = (New-Object System.Text.UTF8Encoding).GetString($wFile.OpenBinary());
						$nsDetail = $wXml.OuterXml.ToLower()
						
						$wFeatureName = $wFeatureName.ToLower()
							
						if($nsDetail -Like "*$wFeatureName*")
						{
							$outFolder = $folder -replace "Workflows/",""

							$outObject = new-object PSObject
							$outObject | add-member -membertype NoteProperty -name "URL" -Value $web2.Url
							$outObject | add-member -membertype NoteProperty -name "Workflow" -Value $outFolder
							$outObject | add-member -membertype NoteProperty -name "Created By" -Value $wFile.Author
							$outObject | add-member -membertype NoteProperty -name "Created Date" -Value $wFile.TimeCreated
							$outObject | add-member -membertype NoteProperty -name "Modified By" -Value $wFile.ModifiedBy
							$outObject | add-member -membertype NoteProperty -name "Modified Date" -Value $wFile.TimeLastModified

							$global:resultsarray += $outObject
						}
					} 
				} 
			}

			# Use recursion to loop through all subfolders.
			foreach ($subFolder in $folder.SubFolders)
			{
				GetFiles($Subfolder)
			}
		}

		$WebApplications = Get-SPWebApplication

		foreach($webApp in $WebApplications)
		{
			foreach($site in $webApp.Sites)
			{
				if ((Get-SPSite $site.url -ErrorAction SilentlyContinue) -ne $null) 
				{
					foreach($web in $site.AllWebs)
					{
						if ((Get-SPWeb $web.url -ErrorAction SilentlyContinue) -ne $null) 
						{
							$list1 = $web.Lists.TryGetList("Workflows")
							if($list1 -ne $null)
							{
								GetFiles($list1.RootFolder)
							}
						}
					}
				}
			}
		}

		#output file
		$resultsarray | Export-csv $fileName -notypeinformation

	}
)

CAML Query to Return Items Less Than or Greater Than Now

Quick example how to query a list or library for items created more than 5 minutes ago. You can use the Get-Date cmdlet to increment all sorts of values.

$nowMinus5Minutes = [Microsoft.SharePoint.Utilities.SPUtility]::CreateISO8601DateTimeFromSystemDateTime((Get-Date).AddMinutes(-5))
$nowPlus5Minutes = [Microsoft.SharePoint.Utilities.SPUtility]::CreateISO8601DateTimeFromSystemDateTime((Get-Date).AddMinutes(5))

#get items created less than 5 minutes ago
		$caml = '<Where><Lt><FieldRef Name="Modified" /><Value Type="DateTime">' + $nowMinus5Minutes + '</Value></Lt></Where>'
		$sQuery.Query = $caml

Classic ASP Update Records in Access Error [Microsoft][ODBC Microsoft Access Driver] Operation must use an updateable query.

I was trying to update an Access database from a classic ASP page and encountered this error:

[Microsoft][ODBC Microsoft Access Driver] Operation must use an updateable query.

The fix is outlined here:

http://support.yessoftware.com/kb_article.asp?article_id=72

In a modern OS, you need add the local IUSR account to the folder that holds your database.  The account will need read and write access.

Who knew that classic ASP was so much fun to work with?

List of Classic ASP Errors

Oh what fun it is to update a classic ASP site…

The link below outlines a bunch of common errors and a little detail about each.
https://msdn.microsoft.com/en-us/library/ms681549(v=vs.85).aspx

Number ErrorValueEnum constant Description/Possible causes
3000 adErrProviderFailed Provider failed to perform the requested operation.
3001 adErrInvalidArgument Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another. This error is often caused by a typographical error in an SQL SELECT statement. For example, a misspelled field name or table name can generate this error. This error can also occur when a field or table named in a SELECT statement does not exist in the data store.
3002 adErrOpeningFile File could not be opened. A misspelled file name was specified, or a file has been moved, renamed, or deleted. Over a network, the drive might be temporarily unavailable or network traffic might be preventing a connection.
3003 adErrReadFile File could not be read. The name of the file is specified incorrectly, the file might have been moved or deleted, or the file might have become corrupted.
3004 adErrWriteFile Write to file failed. You might have closed a file and then tried to write to it, or the file might be corrupted. If the file is located on a network drive, transient network conditions might prevent writing to a network drive.
3021 adErrNoCurrentRecord Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.

An attempt was made to update records by using Find or Seek to move the record pointer to the desired record. If the record is not found, EOF will be True. This error can also occur after a failed AddNew or Delete because there is no current record when these methods fail.

3219 adErrIllegalOperation Operation is not allowed in this context.
3220 adErrCantChangeProvider Supplied provider is different from the one already in use.
3246 adErrInTransaction Connection object cannot be explicitly closed while in a transaction. A Recordset or Connection object that is currently participating in a transaction cannot be closed. Call either RollbackTrans or CommitTrans before closing the object.
3251 adErrFeatureNotAvailable The object or provider is not capable of performing the requested operation. Some operations depend on a particular provider version.
3265 adErrItemNotFound Item cannot be found in the collection corresponding to the requested name or ordinal. An incorrect field or table name has been specified.
3367 adErrObjectInCollection Object is already in collection. Cannot append. An object cannot be added to the same collection twice.
3420 adErrObjectNotSet Object is no longer valid.
3421 adErrDataConversion Application uses a value of the wrong type for the current operation. You might have supplied a string to an operation that expects a stream, for example.
3704 adErrObjectClosed Operation is not allowed when the object is closed. The Connection or Recordset has been closed. For example, some other routine might have closed a global object. You can prevent this error by checking the State property before you attempt an operation.
3705 adErrObjectOpen Operation is not allowed when the object is open. An object that is open cannot be opened. Fields cannot be appended to an open Recordset.
3706 adErrProviderNotFound Provider cannot be found. It may not be properly installed.

The name of the provider might be incorrectly specified, the specified provider might not be installed on the computer where your code is being executed, or the installation might have become corrupted.

3707 adErrBoundToCommand The ActiveConnection property of a Recordset object, which has a Command object as its source, cannot be changed. The application attempted to assign a new Connection object to a Recordset that has a Command object as its source.
3708 adErrInvalidParamInfo Parameter object is improperly defined. Inconsistent or incomplete information was provided.
3709 adErrInvalidConnection The connection cannot be used to perform this operation. It is either closed or invalid in this context.
3710 adErrNotReentrant Operation cannot be performed while processing event. An operation cannot be performed within an event handler that causes the event to fire again. For example, navigation methods should not be called from within a WillMove event handler.
3711 adErrStillExecuting Operation cannot be performed while executing asynchronously.
3712 adErrOperationCancelled Operation has been canceled by the user. The application has called the CancelUpdate or CancelBatch method and the current operation has been canceled.
3713 adErrStillConnecting Operation cannot be performed while connecting asynchronously.
3714 adErrInvalidTransaction Coordinating transaction is invalid or has not started.
3715 adErrNotExecuting Operation cannot be performed while not executing.
3716 adErrUnsafeOperation Safety settings on this computer prohibit accessing a data source on another domain.
3717 adWrnSecurityDialog For internal use only. Don’t use. (Entry was included for the sake of completeness. This error should not appear in your code.)
3718 adWrnSecurityDialogHeader For internal use only. Don’t use. (Entry included for the sake of completeness. This error should not appear in your code.)
3719 adErrIntegrityViolation Data value conflicts with the integrity constraints of the field. A new value for a Field would cause a duplicate key. A value that forms one side of a relationship between two records might not be updatable.
3720 adErrPermissionDenied Insufficient permission prevents writing to the field. The user named in the connection string does not have the proper permissions to write to a Field.
3721 adErrDataOverflow Data value is too large to be represented by the field data type. A numeric value that is too large for the intended field was assigned. For example, a long integer value was assigned to a short integer field.
3722 adErrSchemaViolation Data value conflicts with the data type or constraints of the field. The data store has validation constraints that differ from the Field value.
3723 adErrSignMismatch Conversion failed because the data value was signed and the field data type used by the provider was unsigned.
3724 adErrCantConvertvalue Data value cannot be converted for reasons other than sign mismatch or data overflow. For example, conversion would have truncated data.
3725 adErrCantCreate Data value cannot be set or retrieved because the field data type was unknown, or the provider had insufficient resources to perform the operation.
3726 adErrColumnNotOnThisRow Record does not contain this field. An incorrect field name was specified or a field not in the Fields collection of the current record was referenced.
3727 adErrURLDoesNotExist Either the source URL or the parent of the destination URL does not exist. There is a typographical error in either the source or destination URL. You might have http://mysite/photo/myphoto.jpg when you should actually have http://mysite/photos/myphoto.jpg instead. The typographical error in the parent URL (in this case, photo instead of photos) has caused the error.
3728 adErrTreePermissionDenied Permissions are insufficient to access tree or subtree. The user named in the connection string does not have the appropriate permissions.
3729 adErrInvalidURL URL contains invalid characters. Make sure the URL is typed correctly. The URL follows the scheme registered to the current provider (for example, Internet Publishing Provider is registered for http).
3730 adErrResourceLocked Object represented by the specified URL is locked by one or more other processes. Wait until the process has finished and attempt the operation again. The object you are trying to access has been locked by another user or by another process in your application. This is most likely to arise in a multi-user environment.
3731 adErrResourceExists Copy operation cannot be performed. Object named by destination URL already exists. Specify adCopyOverwrite to replace the object. If you do not specify adCopyOverwrite when copying the files in a directory, the copy fails when you try to copy an item that already exists in the destination location.
3732 adErrCannotComplete The server cannot complete the operation. This might be because the server is busy with other operations or it might be low on resources.
3733 adErrVolumeNotFound Provider cannot locate the storage device indicated by the URL. Make sure the URL is typed correctly. The URL of the storage device might be incorrect, but this error can occur for other reasons. The device might be offline or a large volume of network traffic might prevent the connection from being made.
3734 adErrOutOfSpace Operation cannot be performed. Provider cannot obtain enough storage space. There might not be enough RAM or hard-drive space for temporary files on the server.
3735 adErrResourceOutOfScope Source or destination URL is outside the scope of the current record.
3736 adErrUnavailable Operation failed to complete and the status is unavailable. The field may be unavailable or the operation was not attempted. Another user might have changed or deleted the field you are trying to access.
3737 adErrURLNamedRowDoesNotExist Record named by this URL does not exist. While attempting to open a file using a Record object, either the file name or the path to the file was misspelled.
3738 adErrDelResOutOfScope The URL of the object to be deleted is outside the scope of the current record.
3747 adErrCatalogNotSet Operation requires a valid ParentCatalog.
3748 adErrCantChangeConnection Connection was denied. The new connection you requested has different characteristics than the one already in use.
3749 adErrFieldsUpdateFailed Fields update failed. For further information, examine the Status property of individual field objects. This error can occur in two situations: when changing a Field object’s value in the process of changing or adding a record to the database; and when changing the properties of the Field object itself.

The Record or Recordset update failed due to a problem with one of the fields in the current record. Enumerate the Fields collection and check the Status property of each field to determine the cause of the problem.

3750 adErrDenyNotSupported Provider does not support sharing restrictions. An attempt was made to restrict file sharing and your provider does not support the concept.
3751 adErrDenyTypeNotSupported Provider does not support the requested kind of sharing restriction. An attempt was made to establish a particular type of file-sharing restriction that is not supported by your provider. See the provider’s documentation to determine what file-sharing restrictions are supported.

The workflow could not update the item, possibly because one or more columns for the item require a different type of information.

SharePoint Designer workflow error:
The workflow could not update the item, possibly because one or more columns for the item require a different type of information.

If you look at the workflow history nothing of value is there to clue you into what field is broken.

To track down what field is broken, I added a Pause action to my Step. Then I added a Log message before each action. Doing this helped track down the broken field.

The workflow could not update the item

Once you get the workflow working again, remember to clean up the added Log actions.

In my case, the workflow was trying to update a Person / Group field with an employee that no longer worked at the company.

System.IO.FileNotFoundException: The web application at could not be found

Online, I found a lot of different solutions to the error but none of them would solve my issue. I had written a console app that reads data from a SharePoint library, then processes the data. The process is started using a scheduled task and runs under the context of a service account. The account had contribute permissions on the library and read access to the site.

The solution:
On the SharePoint Config and Content database(s), grant the account SharePoint_Shell_Access.

After doing this, I noticed this message in the app’s call stack:

 executed on connection "Data Source=SPDevDB;Initial Catalog=SP2010_Dev_Config;Integrated Security=True;Enlist=False;Connect Timeout=15", building a SqlDataReader.
[7132]

After seeing the message, it was clear that the app was first trying to connect to the config db, then it would connect to the site/library objects.