Showing posts with label Dummies. Show all posts
Showing posts with label Dummies. Show all posts

Saturday, 25 June 2016

PowerShell Basics for Dummies - ConvertTo-Html

PowerShell Basics for Dummies - ConvertTo-Html


ConvertTo-Html:

  • Converts Microsoft .NET Framework objects into HTML that can be displayed in a Web browser.
  • The ConvertTo-Html cmdlet converts .NET Framework objects into HTML that can be displayed in a Web browser. You can use this cmdlet to display the output of a command in a Web page.
  • You can use the parameters of ConvertTo-Html to select object properties, to specify a table or list format, to specify the HTML page title, to add text before and after the object, and to return only the table or list fragment, instead of a strict DTD page.
  • When you submit multiple objects to ConvertTo-Html, Windows PowerShell creates the table (or list) based on the properties of the first object that you submit. If the remaining objects do not have one of the specified properties, the property value of that object is an empty cell. If the remaining objects have additional properties, those property values are not included in the file.

Get-EventLog -LogName "Windows PowerShell" | ConvertTo-Html > PSEventlog.htm

  • The command sends the HTML code to the PSEventlog.htm file.

PowerShell Basics for Dummies - Get-Service

PowerShell Basics for Dummies - Get-Service


Get-Service:

  • Gets the services running on the specified computers. The default is the local computer.

 Get-Service -ComputerName "Server1"

  • This command gets the services on the "Server1" remote computer.

  • Because the ComputerName parameter of Get-Service does not use Windows PowerShell remoting, you can use this parameter even if the computer is not configured for remoting in Windows PowerShell.


Get-Service "wmi*"

  • This command retrieves services with service names that begin with WMI

Powershell Basics for Dummies - Get-ExecutionPolicy

Powershell Basics for Dummies - Get-ExecutionPolicy

Get-ExecutionPolicy

  • If you'll need to know what execution policy is in use before you attempt to run a script. You can find out by using the Get-ExecutionPolicy command.
  • This will show the current status of Execution policy.
Get-ExecutionPolicy

Four levels of security exist:

  • Restricted — Restricted is the default execution policy and locks PowerShell down so that commands can be entered only interactively. PowerShell scripts are not allowed to run.
  • All Signed — If the execution policy is set to All Signed then scripts will be allowed to run, but only if they are signed by a trusted publisher.
  • Remote Signed — If the execution policy is set to Remote Signed, any PowerShell scripts that have been locally created will be allowed to run. Scripts created remotely are allowed to run only if they are signed by a trusted publisher.
  • Unrestricted — As the name implies, Unrestricted removes all restrictions from the execution policy.

Powershell Basics for Dummies - Set-ExecutionPolicy

Powershell Basics for Dummies - Set-ExecutionPolicy

Set-ExecutionPolicy

  • By Default Microsoft has disabled scripting  in an effort to prevent malicious code from executing in a PowerShell environment. 
  • You should use Set-ExecutionPolicy command to control the level of security surrounding PowerShell scripts. 

Four levels of security exist:

  • 1. Restricted — Restricted is the default execution policy and locks PowerShell down, so that commands can be entered only interactively. PowerShell scripts are not allowed to run.
  • 2. All Signed — If the execution policy is set to All Signed then scripts will be allowed to run, but only if they are signed by a trusted publisher like Microsft etc.
  • 3.Remote Signed — If the execution policy is set to Remote Signed, any PowerShell scripts that have been locally created will be allowed to run. Scripts created remotely are allowed to run only if they are signed by a trusted publisher like Microsoft.
  • 4. Unrestricted — Unrestricted removes all restrictions from the execution policy.

You can set an execution policy by entering the Set-ExecutionPolicy command followed by the name of the policy. For example, if you wanted to allow scripts to run in an All Signed manner you could type:

Set-ExecutionPolicy All Signed