Variables: These are simply an object that contains something. Variables can be identified by a preceding $, such as the “new” variable that follows: We populate variables with the = sign. The following instantiates (creates an instance of) a SharePoint web object (called an SPWeb object in the Server Object Model vernacular): You can name your variables pretty much whatever you like, though there are rules – google them if you are curious, since .Net object naming conventions are slightly out of the scope of this document. The SharePoint Server Object Model: This is what makes SharePoint Administration on the command line sooo much easier and fun vs the GUI. It does have some requirements however – mainly, you must be granted SPShellAdmin privilege over every database you wish to perform operations on. If you are in a regular PowerShell screen, you can add the SharePoint assembly by typing the following: If you do not have SPShellAdmin, you will likely receive an error talking about the farm not being available …. The following is a command that I run with one of our Farm Admin service accounts every time I find my account does not have SPShellAdmin (we have about 20 different farms at work). Just a note – this command must be run with an account that already has SPShellAdmin – it also must be run with the SharePoint Management Shell app with administrative / elevated privileges: What this command does is it grabs ALL of the database names that the current SharePoint databases and stores them in that $spdb variable and also says that within the loop, they will individually be addressed using the $_ variable. The $username variable is the username you wish to get SPShellAdmin privilege to. The ForEach loop says that, for every item located in the $spdb variable (which is every one of the databases, you can view that simply by typing get-spdatabase), the command between the { } should be ran. Within the { }, you will see the $_.id – what this is saying is that the particular database item’s ID (GUID) should be used with the –database parameter, and your username used in the –username parameter. Assuming all went well you will be presented with my favorite output of all absolutely nothing! This counts as one of those ‘no news is good news’ situations. Moving on …. Now that we have authorization to be in here, sign out of your service account and sign in with your regular account. After you are back in, pull open a regular old PoSH window and add the SharePoint assembly: to see all the web applications in your farm. Lets put one in a variable: Next, type Get-SPWebApplication You should see a giant list of stuff on your screen now – these are all of the member objects that are available through the Object Model to you for play with. You should now see a list of all the site collections you previously created in your web application. Play around with get-member and select using the | …. That vertical line is called a Pipe – it is how you can pass objects from one command to another. You may also want to try hitting the TAB button on a partially finished command to see what happens (this is called Tab-Completion and is by far my fav part of modern command line interfaces!)
Fix: Unable to lock the administration directory[FIX] Sharepoint not Showing Whole Word DocumentHow to Remove the Security Error when Downloading ‘.msg’ Email Attachments from…Using PowerShell to Investigate Windows Defender’s Malware Signature Definitions