Showing posts with label powershell. Show all posts
Showing posts with label powershell. Show all posts

Tuesday, December 18, 2018

PowerShell 101 - Basics


How to get Help

https://docs.microsoft.com/en-us/powershell

Help
Get-Help
Help vs Get-Command
search command using Bing or google

Search using https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/?view=powershell-6

How to Edit

Tab Complete
History

What is Piping?

Select
More

example: Get-Process | More
example: Get-Process | Select * | More

example: Get-Command | Measure-Object

Variables?

variables
collections
array
Get-Member

example: $temp = Get-Process
example: $temp | Get-Member
example: $temp = Get-Process[0]


Note if help files are missing run update-help or go here to help online


How to get Help

Help
Get-Help
Help vs Get-Command
search

How to Edit

Tab Complete
History

What is Piping?

Select
More
Measure

Variables?

collections
array
get member

Editor

Command line vs ISE

Keyboard Shortcuts

https://msdn.microsoft.com/en-us/powershell/scripting/core-powershell/ise/keyboard-shortcuts-for-the-windows-powershell-ise
https://technet.microsoft.com/en-us/library/ff678293.aspx

Wednesday, February 21, 2018

PowerShell Courses Books Tools and Training

Free Books

List of Free PowerShell eBooks (11-2018)
https://www.hofferle.com/list-of-free-powershell-ebooks/

List of Free Books – PowerShell

 https://cincypowershell.org/Resources/

Huge List of Free Books – Including PowerShell

http://thecloudengineer.blogspot.com/2011/12/sharepointbooks.html

Free Microsoft Books – Including PowerShell

http://thecloudengineer.blogspot.com/2011/12/sharepointbooks.html

Free eBooks – PowerShell

https://powershell.org/category/books

https://leanpub.com/u/devopscollective

Scripting Guy
http://blogs.technet.com/b/heyscriptingguy/

Windows PowerShell Survival Guide (11-2018)
https://social.technet.microsoft.com/wiki/contents/articles/183.windows-powershell-survival-guide.aspx

Free Training

PowerShell and Active Directory Essentials

https://info.varonis.com/thank-you/course/powershell

Latest Books Recommended by Students

PowerShell for Dummies
https://www.amazon.com/Windows-PowerShell-Dummies-Steve-Seguis/dp/0470371986/ref=sr_1_1

Learn Windows PowerShell in a Month of Lunches

https://www.amazon.com/Learn-Windows-PowerShell-Month-Lunches/dp/1617294160/ref=sr_1_1

Great list from Ashley McGlone
https://blogs.technet.microsoft.com/ashleymcglone/2016/04/01/powershell-video-training-from-microsoft/   

Examples

Find Duplicate Files With PowerShell (11-2018)
http://blog.codeassassin.com/2007/10/13/find-duplicate-files-with-powershell/

Tools

Idera PowerShell Plus is now free
Free tool to learn and master PowerShell fast

  • Learn PowerShell fast with the interactive learning center
  • Execute PowerShell quickly and accurately with a Windows UI console
  • Access, organize and share pre-loaded scripts from the QuickClick™ library
  • Code & Debug PowerShell 10X faster with the advanced script editor
https://www.idera.com/Free-Tools/PowerShell-Plus/

User Groups


Cincy OH -
http://powershellgroup.org/cincinnati.oh
Columbus OH - http://powershellgroup.org/central.oh

Older Books on PowerShell


General - Must Have!

Automating Microsoft Windows Server 2008 R2 with Windows PowerShell 2.0
Windows PowerShell 2.0 allows you to automate nearly any task for managing Windows Server, going from dozens of clicks to a single command, and repeated tasks to automated tasks. Using screen shots and helpful exercises, this book walks you through the many benefits of automating Windows Server with PowerShell 2.0, such as allowing for scalable, flexible, and rapid deployments and changes; increasing cost effectiveness; providing a timely return on IT investment; lowering labor headcount; creating secure computing environments; and establishing reliable enterprise infrastructures. In addition, real-world examples provide reinforced learning, aimed at ensuring that you work as efficiently and effectively as possible by automating both simple and complex administrative tasks with Powershell 2.0.
Details from
Wiley Publishing  Matt Hester http://blogs.technet.com/b/matthewms/

SharePoint - Must Have!

Automating SharePoint 2010 with Windows PowerShell 2.0
Imagine being able to perform a task that requires dozens of clicks with just a single command, or automate a series of identical tasks rather than repeat them. This book shows you how to do just that?and more?by using Windows PowerShell cmdlets with SharePoint 2010. Focused on everyday and frequently performed tasks, this invaluable guide provides PowerShell solutions for maintaining a SharePoint environment and explains how more than 500 cmdlets that come with SharePoint 2010 allows you to automate just about anything. Step-by-step instructions walk you through the necessary concepts and real-world examples enhance your learning process.
Details from
Amazon  Gary LaPoint http://blog.falchionconsulting.com/

Recommended by students ...

Windows PowerShell 2 For Dummies
Prepare for the future of Microsoft automation with this no-nonsense guide
Windows PowerShell 2 is the scripting language that enables automation within the Windows operating system. Packed with powerful new features, this latest version is complex, and Windows PowerShell 2 For Dummies is the perfect guide to help system administrators get up to speed.
Written by a Microsoft MVP with direct access to the program managers and developers, this book covers every new feature of Windows PowerShell 2 in a friendly, easy-to-follow format.
  • Windows PowerShell 2 is the updated scripting language that enables system administrators to automate Windows operating systems
  • System administrators with limited scripting experience will find this book helps them learn the fundamentals of Windows PowerShell 2 quickly and easily
  • Translates the jargon and complex syntax of Windows PowerShell 2
  • Covers script debugging improvements, the ability to invoke commands remotely, and the new user interface
  • Uses real-world applications to clarify the theory, fundamentals, and techniques of the scripting language
  • Written by a Microsoft MVP with direct access to the developers of Windows PowerShell 2
Windows PowerShell 2 For Dummies makes this tool easily accessible to administrators of every experience level.


Training Courses



10325A Automating Administration with Windows PowerShell 2.0

This course provides students with the knowledge and skills  to utilize Windows PowerShell for administering and automating administration of  Windows based servers. This course is intended for IT Professionals already  experienced in general Windows Server and Windows Client administration,  including Active Directory administration. No prior experience with any version  of Windows PowerShell, or any scripting language, is assumed. Topics covered include:

10961 Automating Administration with Windows PowerShell 3.0
Learn how with Windows PowerShell 3.0, you can remotely manage single or multiple Windows-based servers and automate day-to-day management and administration tasks.
This five day course provides students with the fundamental knowledge and skills to use Windows PowerShell 3.0 for administering and automating administration of Windows based servers. It focuses on primary Windows PowerShell command-line features and techniques, and will provide prerequisite skills supporting many different Microsoft products. This includes Windows Server, Windows Client, Exchange Server, SharePoint Server, SQL Server, System Center, and more. In keeping with that goal, this course will not focus on any one of those products, although Windows Server (which is the common platform for all of those) will serve as the example for the techniques being taught.

MVA


Basic - http://www.microsoftvirtualacademy.com/training-courses/getting-started-with-powershell-3-0-jump-start
Advanced - http://www.microsoftvirtualacademy.com/training-courses/advanced-tools-scripting-with-powershell-3-0-jump-start

Intermediate | Published: 30 July 2013  | Getting Started with Microsoft PowerShell
Instructor(s):
Jason Helmick and Jeffrey Snover


https://mva.microsoft.com/en-us/training-courses/getting-started-with-microsoft-powershell-8276?l=r54IrOWy_2304984382

Tuesday, November 28, 2017

Windows 10 PowerShell Reference Guide

Course 20697-1 Implementing and Managing Windows 10

Module 3

Get-ExecutionPolicy

Set-ExecutionPolicy Unrestricted

Get-PrinterProperty –PrinterName “HP Photosmart 7520”
Note
: The property named Config:DuplexUnit is set to TRUE.

Set-PrinterProperty –PrinterName “HP Photosmart 7520” –PropertyName “Config:DuplexUnit” –Value FALSE
Note:
You must use all caps for the TRUE or FALSE values.

Get-PrinterProperty –PrinterName “HP Photosmart 7520”
Note:
The property named Config:DuplexUnit is now FALSE.

# *** Answer *** List Running Services in Green

$services = get-service

foreach ($service in $services) {

    if ($service.status –eq “Running”) {

        $color = “Green” }

    Else {

        $color = “Red” }

    write-host $service.Name “ – “ $service.Status –ForegroundColor $color

}

write-host “A total of “ $services.count “services were evaluated”

write-host “Script execution is complete” –ForegroundColor gray –BackgroundColor Black

Additional Notes Try …

$services | Group-Object -Property status

Module 4

Get-NetIPAddress

test-connection LON-DC1

Get-DnsClientCache

Clear-DnsClientCache

test-connection www

Get-DnsClientCache | fl

Resolve-Dnsname LON-DC1 | fl

Module 5

$MaxSize = (Get-PartitionSupportedSize –DriveLetter e).sizeMax
Resize-Partition –DriveLetter e –Size $MaxSize

Clear-Disk –Number 1 –RemoveData
Note: Delete all partitions from disk

Get-Disk | Where partitionstyle -eq 'raw' | Initialize-Disk -PartitionStyle MBR

Module 6

Install-WindowsFeature FS-SyncShareService
Note: After the feature installs, you will receive a warning message because Windows automatic updating is not enabled. You can ignore the warning.

Module 7

add-appxpackage \\lon-dc1\apps\app1.appx

Module 8

Sorry but no noteworthy PowerShell

Module 9

Invoke-Gpupdate –force

Module 10

Run Get-NetIPsecMainModeSA

Note: To examine the Main Mode Security Associations (SAs), at the Windows PowerShell prompt, type the following cmdlet, and then press Enter:
Get-NetIPsecMainModeSA

Run Get-NetIPsecQuickModeSA

Note: To examine the Quick Mode SAs, at the Windows PowerShell prompt, type the following cmdlet, and then press Enter:
Get-NetIPsecQuickModeSA

Module 11

Sorry but no noteworthy PowerShell

Module 12

Sorry but no noteworthy PowerShell

Tuesday, October 4, 2016

SharePoint PowerShell

Update

DBATools is a free PowerShell module with over 180 SQL Server administration, best practice and migration commands included
https://dbatools.io/

Github
https://github.com/sharepoint

Codeplex
http://www.codeplex.com/site/search?TagName=Sharepoint

Add Online Modules
http://sharepoint-tricks.com/install-update-uninstall-cmdlets-for-sharepoint-online

More from The Cloud Engineer

https://thecloudengineer.blogspot.com/2016/09/powershell-toolbox-for-sharepoint.html

Older News

Strange Error
http://sharepoint.stackexchange.com/questions/17247/spsite-allwebs-returns-error

PowerShell Articles from Mike Smith
http://sharepointpromag.com/author/michael-t-smith

http://sharepointpromag.com/sharepoint-2010/inventorying-sharepoint-using-powershell

http://sharepointpromag.com/sharepoint/windows-powershell-scripts-sharepoint-info-files-pagesweb-parts

http://sharepointpromag.com/sharepoint-2013/exploring-sharepoint-users-groups-and-security-using-powershell

http://sharepointpromag.com/sharepoint/exploring-and-inventorying-sharepoint-using-powershell-part-4-finding-and-resetting-custo

http://techtrainingnotes.blogspot.cz/2011/06/sharepoint-how-to-change-default-home.html

Creating Content Types (and Site Columns) with PowerShell

http://www.rbradbrook.co.uk/blog/2013/03/10/creating-content-types-and-site-columns-with-powershell/

Log Info
http://zimmergren.net/technical/sp-2010-find-error-messages-with-a-correlation-id-token-in-sharepoint-2010

General Info

Great Tool
http://www.sapien.com/software/powershell_studio

Great site with a ton of scripts
http://blogs.technet.com/b/onescript/p/sharepoint.aspx

Just found but untested

http://social.technet.microsoft.com/wiki/contents/articles/20692.sharepoint-get-set-and-copy-user-profile-properties-using-powershell.aspx

ISE http://thecloudengineer.blogspot.com/2011/10/create-ise-enabled-for-sharepoint.html

Command Builder
http://www.microsoft.com/resources/TechNet/en-us/Office/media/WindowsPowerShell/WindowsPowerShellCommandBuilder.html

2013
Complete List - Index of Windows PowerShell cmdlets for SharePoint 2013
http://technet.microsoft.com/en-us/library/ff678226.aspx

2010
Complete List - Index of Windows PowerShell cmdlets for SharePoint 2010
http://technet.microsoft.com/en-us/library/ff678226(v=office.14).aspx

Great Reference to PowerShell in SharePoint 2010
http://technet.microsoft.com/en-us/library/ff678226.aspx

More from Powershell101
Users
http://powershell101.blogspot.com/2012/06/sharepint-users.html

Confirmed PS1 Examples

Enumerating SharePoint Permissions and Active Directory
New and improved http://briantjackett.com/archive/2013/07/01/powershell-script-to-enumerate-sharepoint-2010-or-2013-permissions-and.aspx

http://geekswithblogs.net/bjackett/archive/2009/04/24/the-power-of-powershell-and-sharepoint-enumerating-sharepoint-permissions-and.aspx

Capture and report on all SharePoint permissions through a site collection http://localgovernmentsharepoint.wordpress.com/2012/01/25/powershell-script-to-capture-and-report-on-all-sharepoint-permissions-through-a-site-collection/

Open Port Audit
http://gallery.technet.microsoft.com/Security-hardening-for-c425db1d

Potential Examples

Set AD changes needed for UPSA via powershell
http://blog.kuppens-switsers.net/2012/02/setting-replicating-directory-changes-using-powershell/

General Code from Engineers at PointBeyond
http://blog.pointbeyond.com/

Copy List
http://adicodes.com/copy-or-replace-list-items-in-powershell/#!

AD Lockout
http://mikefrobbins.com/2013/11/29/powershell-script-to-determine-what-device-is-locking-out-an-active-directory-user-account/

Move Site Collections
http://alinimer.com/2012/06/10/from-the-field-move-a-site-collection-to-new-content-db-with-new-managed-path/

Remove Unused Users
http://weblogs.asp.net/bsimser/archive/2013/02/12/powershell-tools-removing-orphaned-users-from-sharepoint.aspx

Long List of examples
http://powershellscripts.com/category.asp?cat=SharePoint

Adding users and claims to a site from PowerShell
http://blogs.msdn.com/b/brporter/archive/2010/12/02/adding-users-and-claims-to-a-site-from-powershell.aspx

Changing the Item-Level Permissions Settings for a Document Library requires PowerShell http://www.hersheytech.com/Blog/SharePoint/tabid/197/entryid/28/Default.aspx

Create a full site hierarchy
http://reality-tech.com/2012/03/07/scripts-to-create-scripts/

My Site
http://gallery.technet.microsoft.com/scriptcenter/Pre-Provision-SharePoint-ec781ee9

Thursday, October 8, 2015

Remote PowerShell

Updates

 

Security

Who’s afraid of PowerShell security?
https://blogs.technet.microsoft.com/ashleymcglone/2016/06/29/whos-afraid-of-powershell-security/

Defending Against PowerShell Attacks (2017)
https://blogs.msdn.microsoft.com/powershell/2017/10/23/defending-against-powershell-attacks/

ISE

PowerShell Remoting With Integrated Scripting Environment–ISE
http://blogs.technet.com/b/rmilne/archive/2015/02/02/using-exchange-powershell-remoting-with-integrated-scripting-environment-ise.aspx

Security

http://blogs.msdn.com/b/powershell/archive/2013/12/16/powershell-security-best-practices.aspx

Reflective DLL Loading with PowerShell:
http://www.youtube.com/watch?v=OAd68_SYQc8

Living off the Land:
http://www.youtube.com/watch?v=j-r6UonEkUw

Get-Help about_Group_Policy_Settings
http://technet.microsoft.com/en-us/library/jj149004.aspx

Constrained PowerShell Endpoints
http://www.youtube.com/watch?v=kmjJLKlL1Wg

PowerShell Language Specification:
http://www.microsoft.com/en-us/download/details.aspx?id=36389

Composing Command Arguments:
http://www.powershellcookbook.com/recipe/XoMw/run-programs-scripts-and-existing-tools

PowerShell Remoting over HTTPS with a self-signed SSL certificate
https://4sysops.com/archives/powershell-remoting-over-https-with-a-self-signed-ssl-certificate/

SharePoint

PowerShell Remoting for SharePoint 2010/2013
http://sharepoint-community.net/profiles/blogs/powershell-remoting-for-sharepoint

SharePoint 2010 with Windows PowerShell Remoting Step by Step
http://blogs.msdn.com/b/opal/archive/2010/03/07/sharepoint-2010-with-windows-powershell-remoting-step-by-step.aspx

Configure Remote PowerShell in SharePoint 2010
http://blogs.msdn.com/b/varun_malhotra/archive/2010/06/10/configure-power-shell-for-remote-use-of-sp-2010.aspx

Original Blog

There are several ways to connect and run PowerShell command remotely.  In this article I want to address the needs of many IT admins that just need quick PowerShell access to run a command or set of commands.

First step is to open your remote computer to PowerShell using GPOs or type

winrm quickconfig

image

Invoke-Command

Now using PowerShell you can run several commands but lets focus first on invoke command

image

Help Invoke-Command –examples is all you need.  Just copy the second example and fill in the blanks.

image

However this does have an annoying issues that we can quickly fix.  Using variables lets set both the computername and user

image

Just substitute the variables for computername and credentials and you are good to go.  Note that the user/password variable is secure for most users Winking smile but more on that later.

image

Enter-PSsession

Since we have variables set for computername and credentials this one is easy.

image

Now connected -Fun commands

image

[System.Net.Dns]::GetHostbyAddress("127.0.0.1")

[System.Net.Dns]::GetHostAddresses(“contoso.com")

image

get-wmiobject win32_service –computername 127.0.0.1

image

get-psdrive

cd hklm:\  (or any other drive)

Old School

Remember you can always type cmd to get the old classic command if needed.  Have Fun!

image

cd hklm:\get

References

Thanks always to Ed and Theresa Wilson for inspiration http://www.edwilson.com/

Good Articles on Remote PowerShell
http://technet.microsoft.com/en-us/magazine/gg981683.aspx
http://blogs.technet.com/b/heyscriptingguy/archive/2011/11/16/configure-powershell-remoting-and-use-remote-commands.aspx

system.net namespace

 http://msdn.microsoft.com/en-us/library/system.net.aspx

 http://msdn.microsoft.com/en-us/library/system.net.networkinformation.aspx

Old but not thrown out yet
http://blogs.msdn.com/b/powershell/archive/2008/05/10/remoting-with-powershell-quickstart.aspx

Tuesday, September 1, 2015

SharePoint Search Service Application PowerShell

 

Check the crawl status of all content sources in your SSA where SSA is search service application.

Get-SPEnterpriseSearchCrawlContentSource -SearchApplication "Search Service Application" | select Name, CrawlStatus | format-table –autosize

image

Total number of list items in a SharePoint Web Application

https://blogs.technet.microsoft.com/nishants/2012/05/04/total-number-of-list-items-in-a-sharepoint-web-application/

Tuesday, May 12, 2015

PowerShell Tip #3 - Integrated Scripting Environment

 

There are several ISE or Integrated Scripting Environments available for PowerShell.  The cost runs from free to several hundred dollars on the high end.

Introducing the Windows PowerShell ISE

https://technet.microsoft.com/en-us/library/dd315244.aspx

ISESteroidsTM is new add-on for the Windows PowerShell ISE editor

http://www.powertheshell.com/isesteroids/

PowerShell Studio 2015

The premier Windows PowerShell integrated scripting and tool-making environment available.

https://www.sapien.com/software/powershell_studio

SharePoint

http://thecloudengineer.blogspot.com/2011/10/create-ise-enabled-for-sharepoint.html

Run as Administrator

http://powershell101.blogspot.com/2014/07/ise.html

PowerShell Tip: #2 – SharePoint PowerShell

I love using the ISE to make building your scripts easier and using F5 and F8 keys to help run your scripts.  But I need to use the ISE on SharePoint. No problem just add the snap-in.  But wait, the snap-in goes away when you close the ISE.  No problem just add the SharePoint snap-in to your profile.

http://thecloudengineer.blogspot.com/2011/10/create-ise-enabled-for-sharepoint.html

PowerShell Tip: #1 – PowerShell Demo Scripts

Use ISE to make building your scripts easier.  You can run the script line by line or the entire script by using the F5 and F8 keys to help run your scripts.  If you don’t like the built-in ISE from your OS you can use a free add-on from Idera called PowerShell Plus.

https://www.idera.com/productssolutions/freetools/powershellplus

But during demos you can accidently hit he wrong key, that is run the entire script that kills the demo.  So make sure to include a break at the top of the script

break

Thank you Ashley http://blogs.technet.com/b/ashleymcglone/

Wednesday, April 15, 2015

Active Directory PowerShell

Great question: Can I Create Active Directory Users Based On Excel Input

https://gallery.technet.microsoft.com/scriptcenter/PowerShell-Create-Active-7e6a3978

Great question:  How do I find all the attributes of my users in the Active Directory

First start by starting the Active Directory Module for Windows PowerShell

SNAGHTMLabcee102

Get-ADUser -filter *
image 

Problem is however if you get all the users using -filter * you are missing some attributes. So using a wildcard for the properties will return all.

image 
Using OGV (Out-Gridview) you get a quick view report





Get-ADUser -filter * -properties * | ogv




image



NOTE: You can use the same format above for ad users, ad groups or ad computers

Get-ADComputerUser -filter * -properties * | ogv

Get-ADGroup -filter * -properties * | ogv

Get-ADUser -filter * -properties * | ogv




SNAGHTMLabdebe56



Hope that Helps, Happy PowerShelling

Monday, February 2, 2015

PowerShell Version versus Operation System

Windows

 

XP SP2

XP SP3

Vista

Vista SP1

7

7 SP1

8

8.1

10

1.0

X

 

X

           

2.0

 

X

 

   X

X

       

3.0

         

X

X

   

4.0

             

X

 

5.0

             

O

X

X – Installed
O – Optional

Windows Server

 

2003

2008

2008  SP1

2008 R2

2012

2012 R2

2016

1.0

X

O

         

2.0

     

X

     

3.0

   

X

X

X

   

4.0

         

X

 

5.0

         

O

X

X – Installed
O – Optional

Reference

https://msdn.microsoft.com/en-us/powershell/scripting/setup/windows-powershell-system-requirements

https://4sysops.com/archives/powershell-versions-and-their-windows-version/

Wednesday, December 17, 2014

Parsing Log File with PowerShell

Interesting article

http://matthewyarlett.blogspot.co.uk/2014/11/quick-and-dirty-parsing-logs-with.html

here is the code for reference

# Set the path to the log files            
$path = "C:\Temp\Logs"
# Get a collection of all the log files (anything ending in .log)
$files = Get-ChildItem -Path $path -Filter "*.log"
# Pipe the collection of log files to the ForEach-Object cmdlet
# (the alias of ForEach-Object is %)
$files | %{
# Call the OpenText method, to return a System.IO.StreamReader object
$file = $_.OpenText();
# Record the current line number (to use in the console output)
$lineNum = 1;
Write-Host "Checking file"$_.Name -f Yellow;
# Use the EndOfStream method (which returns true when you have reach the end
# of the file), read each line of the file.
while($file.EndOfStream -ne $true)
{
# Read the next line in the file
$line = $file.ReadLine();
if($line -ne $null)
{
# Use the String ToLower and Contains methods to check for occurances
# of the strings (or values) you need to check the file for
# In this example, I'm looking for any instances of the text "error" or "exception"
if($line.ToLower().Contains("error") -or $line.ToLower().Contains("exception"))
{
# If the current lines contains a match, write the line number
# and line text out to the console
Write-Host "Line: $lineNum " -NoNewline -ForegroundColor Green;
Write-Host $line -f Red;
}
}
# Increment the line number
$lineNum++;
}
}

Wednesday, July 2, 2014

ISE–PowerShell Integrated Scripting Environment

Here is some fun with the Windows PowerShell Integrated Scripting Environment or ISE

Start ISE

simply type ise

Start ISE as administrator

start-process PowerShell_ISE –verb RunAs

Customize ISE for SharePoint

http://thecloudengineer.blogspot.com/2011/10/create-ise-enabled-for-sharepoint.html

Configuring the PowerShell ISE for use with Git and GitHub


http://mikefrobbins.com/2016/02/09/configuring-the-powershell-ise-for-use-with-git-and-github/