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/