programming4us
programming4us
WEBSITE

Sharepoint 2013 : PowerShell Basics (part 2)

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

What Are Console Commands?

A handful of what I like to call console commands stem from the good ol’ DOS days. They have been available in command prompts since then, with the current PowerShell consoles included. These commands provide standard directory navigation, file handling, and screen handling.

Several common console commands follow:

cd: Changes the directory

cls: Clears the console screen

dir: Displays a listing of the current directory (folder)

type: Used with a text-based filename and displays the contents of a text file


Tip

These commands have been grouped within PowerShell as Aliases. To see all of the available aliases use Get-Alias.

Path Environment Variable


Scenario/Problem: You have scripts within a local folder which you want PowerShell to recognize such that you do not need to use the full path name.


Solution: Add the local directory path to the PSModulePath variable.

You add the local folder’s path to the PSModule environment variable by entering the following command in the PowerShell command prompt (substituting <folder path> with the local directory path), as shown in Listing 2.2.

Listing 2.2. Adding a Folder Path to the PSModulePath


$env:PSModulePath = $env:PSModulePath + ";c:\<folder path>"



Tip

Add the same exact command line into the PowerShell profile configuration file to always have your local folder added to the PSModulePath. 

Running Unsigned Scripts


Scenario/Problem: You need to be able to run unsigned scripts within PowerShell.


Solution: Use the Set-ExecutionPolicy command.

To run unsigned scripts, you must change the execution policy:

Set-ExecutionPolicy remotesigned

You are prompted with a confirmation. Enter Y and press Enter (or just press Enter—Y is the default).

In some cases, you must set the policy to Unrestricted:

Set-ExecutionPolicy unrestricted

Disabling the Confirmation Prompt


Scenario/Problem: You need to automatically confirm operations such that a script runs unattended.


Solution: Include the -Confirm parameter with a $false setting.

When running cmdlets , you might receive a confirmation message to confirm the action being processed. If you use these cmdlets in scripts, the script will not run straight through without prompting for the confirmation.

The cmdlets that have a -Confirm optional parameter can be called in unattended mode by passing in -Confirm:$false to the cmdlet, as shown in Listing 3.

Listing 3. Suppressing the Confirmation Prompt Example


Remove-item *.png -Confirm:$false



Note

Not all cmdlets have a –Confirm parameter. Use the help (-?) parameter to verify each cmdlet in question.

Generating Inline Credentials


Scenario/Problem: You need to provide cmdlets with credentials without prompting for them.


Solution: Create a new PSCredential object.

Various cmdlets require SharePoint and/or SQL Server account credentials for proper authentication when performing the desired operations. The examples include using (Get-Credential) as the parameter value, which prompts the user for credentials.

When running these cmdlets in scripts, the prompting for credentials pauses the execution. If you need the script to run straight through, instead of using Get-Credential, you can generate a new PSCredential object inline, as shown in Listing 4.

Listing 4. Generating Inline Credentials Example


(New-Object System.Management.Automation.PSCredential "domain\user",
(ConvertTo-SecureString "password" -AsPlainText -Force))


Therefore, simply substitute (Get-Credential) for the text shown in Listing 2.4 with the proper username and password when using a cmdlet with authentication requirements.

Referencing an Assembly


Scenario/Problem: You want to be able to call methods and/or use objects within a trusted assembly (DLL).


Solution: Use a reflection declaration, and then use a variable to instantiate an object.

You can reference an assembly in your PowerShell script and then use any objects available by assigning them to a variable. Then you can use any methods or properties within your script. No intellisense exists, so you need to know the object model beforehand. Listing 5 demonstrates an example assembly reference and usage.

Listing 5. Referencing and Using a SharePoint Assembly


[Void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.
SharePoint")
[Void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.
SharePoint.Administration")

$spFarm = [Microsoft.SharePoint.Administration.SPFarm]::Local
$spFarmSolutions = $spFarm.Solutions



Tip

Instead of coding and compiling a console application, use a PowerShell script that references the SharePoint assemblies.


Other  
  •  SharePoint 2013 Management Shell : What Is the SharePoint 2013 Management Shell Loading?
  •  Watch Web TV Anywhere (Part 3)
  •  Watch Web TV Anywhere (Part 2)
  •  Watch Web TV Anywhere (Part 1)
  •  YouView brings The Most Extraordinary Way To Watch TV (Part 2)
  •  YouView brings The Most Extraordinary Way To Watch TV (Part 1)
  •  Installing and Configuring SharePoint 2013 : Creating Web Applications and More
  •  Installing and Configuring SharePoint 2013 : Creating the Farm (part 7) - Configuring the App Management Service - Configuring the User Profile Service
  •  Installing and Configuring SharePoint 2013 : Creating the Farm (part 6) - Configuring the App Management Service - Configuring PerformancePoint Services , Configuring the Search Service Application
  •  Installing and Configuring SharePoint 2013 : Creating the Farm (part 5) - Configuring the App Management Service - Configuring the Managed Metadata Service
  •  
    Top 10
    Free Mobile And Desktop Apps For Accessing Restricted Websites
    MASERATI QUATTROPORTE; DIESEL : Lure of Italian limos
    TOYOTA CAMRY 2; 2.5 : Camry now more comely
    KIA SORENTO 2.2CRDi : Fuel-sipping slugger
    How To Setup, Password Protect & Encrypt Wireless Internet Connection
    Emulate And Run iPad Apps On Windows, Mac OS X & Linux With iPadian
    Backup & Restore Game Progress From Any Game With SaveGameProgress
    Generate A Facebook Timeline Cover Using A Free App
    New App for Women ‘Remix’ Offers Fashion Advice & Style Tips
    SG50 Ferrari F12berlinetta : Prancing Horse for Lion City's 50th
    - Messages forwarded by Outlook rule go nowhere
    - Create and Deploy Windows 7 Image
    - How do I check to see if my exchange 2003 is an open relay? (not using a open relay tester tool online, but on the console)
    - Creating and using an unencrypted cookie in ASP.NET
    - Directories
    - Poor Performance on Sharepoint 2010 Server
    - SBS 2008 ~ The e-mail alias already exists...
    - Public to Private IP - DNS Changes
    - Send Email from Winform application
    - How to create a .mdb file from ms sql server database.......
    programming4us programming4us
    programming4us
     
     
    programming4us