Ing. Ondřej Ševeček MCSM:Directory | MVP:Enterprise Security | Certified Ethical Hacker | MCSE:SharePoint | PowerShell.

Slides:



Advertisements
Similar presentations
Introduction to PHP Dr. Charles Severance
Advertisements

Written by: Dr. JJ Shepherd
Rick Toner MCSD, MCPD, MCITP Blog:
C#: Data Types Based on slides by Joe Hummel. 2 UCN Technology: Computer Science Content: “.NET is designed around the CTS, or Common Type System.
Ing. Ondřej Ševeček | GOPAS a.s. | MCSM:Directory | MVP:Enterprise Security | CEH:Certified Ethical Hacker | CHFI:Computer Hacking Forensic Investigator.
Microsoft PowerShell Tom Roeder CS fa. Motivation.NET as a platform shell web server database access Native access to resources eaiser to manage.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
C#.NET C# language. C# A modern, general-purpose object-oriented language Part of the.NET family of languages ECMA standard Based on C and C++
Programming in Java; Instructor:Alok Mehta Objects, Classes, Program Constructs1 Programming in Java Objects, Classes, Program Constructs.
Basic.  PS is a command line interpreter/scripting environment  Designed for.Net  Similar to C#  Easy to instantiate.Net classes  Standardized syntax.
Ing. Ondřej Ševeček MCSM:Directory | MVP:Enterprise Security | Certified Ethical Hacker | MCSE:SharePoint | Smart card.
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
What is RobotC?!?! Team 2425 Hydra. Overview What is RobotC What is RobotC used for What you need to program a robot How a robot program works Framework.
Prepared by Uzma Hashmi Instructor Information Uzma Hashmi Office: B# 7/ R# address: Group Addresses Post message:
Java. Why Java? It’s the current “hot” language It’s almost entirely object-oriented It has a vast library of predefined objects It’s platform independent.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
Bezpečnost Windows pro pokročilé: uživatelské účty GOPAS: | | Ing. Ondřej Ševeček | GOPAS a.s. |
Windows PowerShell Deep Dive 1 Morgan Simonsen Ementor.
What would a real hacker do to your AD GOPAS: | | Ing. Ondřej Ševeček | GOPAS a.s. | MCM: Directory.
PowerShell Basics. o PowerShell is a great way to manipulate server and/or workstation components o It’s geared toward system administrators by creating.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
The Java Programming Language
CSC Java Programming, Fall, 2008 Week 2: Java Data Types, Control Constructs, and their C++ counterparts, September 4.
Lecture 2 Object Oriented Programming Basics of Java Language MBY.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
C Derived Languages C is the base upon which many build C++ conventions also influence others *SmallTalk is where most OOP comes Java and Javascript have.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating.
Bezpečnost Windows pro pokročilé: přístup do sítě GOPAS: | | Ing. Ondřej Ševeček | GOPAS a.s. | MCM:Directory.
Introduction to CS520/CS596_026 Lecture Two Gordon Tian Fall 2015.
Page: 1 การโปรแกรมเชิงวัตถุด้วยภาษา JAVA บุรินทร์ รุจจนพันธุ์.. ปรับปรุง 15 มิถุนายน 2552 Keyword & Data Type มหาวิทยาลัยเนชั่น.
Managing Windows Servers with PowerShell V2 James O’Neill: Evangelist, Microsoft UK Richard Siddaway MVP.
Bezpečnost Windows pro pokročilé: zajímavosti a UAC GOPAS: | | Ing. Ondřej Ševeček | GOPAS a.s. |
Computing with C# and the.NET Framework Chapter 2 C# Programming Basics ©2003, 2011 Art Gittleman.
Ing. Ondřej Ševeček MCSM:Directory | MVP:Enterprise Security | Certified Ethical Hacker | MCSE:SharePoint | Event Filtering.
Variables and Data Types.  Variable: Portion of memory for storing a determined value.  Could be numerical, could be character or sequence of characters.
Copyright Curt Hill Variables What are they? Why do we need them?
Windows PowerShell Introduction 1 Morgan Simonsen Ementor.
Perl Variables: Array Web Programming1. Review: Perl Variables Scalar ► e.g. $var1 = “Mary”; $var2= 1; ► holds number, character, string Array ► e.g.
Windows PowerShell. What is Windows PowerShell? A command-line interface (CLI) A new way of developing Windows and other products to be more manageable.
PowerShell for Developers GOPAS: | | Ing. Ondřej Ševeček | GOPAS a.s. | MCM: Directory Services |
Bezpečnost Windows pro pokročilé: protokoly a sledování přihlášení GOPAS: | | Ing. Ondřej Ševeček.
CSC Java Programming, Spring, 2010 Week 2: Java Data Types, Control Constructs, and their C++ counterparts.
Introduction to C# Anders Hejlsberg Distinguished Engineer Developer Division Microsoft Corporation.
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
Session 02 Module 3: Statements and Operators Module 4: Programming constructs Module 5: Arrays.
Ing. Ondřej Ševeček MCSM:Directory | MVP:Enterprise Security | Certified Ethical Hacker | MCSE:SharePoint | Passwords.
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
Object Oriented Programming Lecture 2: BallWorld.
Ravikanth C.
Coming up Implementation vs. Interface The Truth about variables Comparing strings HashMaps.
Ondřej Ševeček | GOPAS a.s. MCSM:Directory Services | MVP:Enteprise Security | CISA | CEH | CHFI | facebook: ondrej.sevecek.official.
Ing. Ondrej Sevecek MCSM:Directory2012 | MVP:Security | CEH | MCSE:Windows2012 | What would a real hacker do to your AD.
Java and C# - Some Commonalities Compile into machine-independent, language- independent code which runs in a managed execution environment Garbage Collection.
PowerShell for Developers
Objects, Classes, Program Constructs
Computing with C# and the .NET Framework
Server-Side Application and Data Management IT IS 3105 (Spring 2010)
Customizing your device experience with assigned access
Lecturer: Mukhtar Mohamed Ali “Hakaale”
null, true, and false are also reserved.
Conditional Statements
SharePoint and IIS core integration
An overview of Java, Data types and variables
Interfaces.
PHP.
PowerShell Best Practices for SQL DBA’s
Cmdlets “Command-lets”
Presentation transcript:

Ing. Ondřej Ševeček MCSM:Directory | MVP:Enterprise Security | Certified Ethical Hacker | MCSE:SharePoint | PowerShell for developers

Why the admins use PowerShell  Newer command line marketing –older VBScript still supported but with limited functionality  Script from command line or textual.PS1 files –extensive object oriented pipeline –support for CMD, EXE, D/COM, NET (plus Win32API through PINVOKE)

Why developers might be interested  Provide Admins with familiar interface for custom applications –own cmdlets in NET  Automate own tasks –builds, file distribution, signing, packaging etc.  Develop installation tasks –MSIEXEC custom actions - external  Test / validate / proof of concept –which is non-compiled, quickly written

Example: Object pipe Get-Process, Stop-Process Export-Csv, Import-Csv Import-CliXml, Export-CliXml CERTUTIL | ConvertFrom-Csv New-Object System.DirectoryServices.DirectoryEntry New-Object System.DirectoryServices.DirectorySearcher [System.Collections.ArrayList] [System.Collections.Hashtable] DSQUERY | Get-WmiObject

PowerShell versions  Version 1 –download for Windows XP and 2003 and Vista –built into Windows 2008  Version 2 –download for Windows XP and 2003, Vista, 2008 –built into Windows 7 and 2008 R2 –NetFx 2.0 CLR  Version 3 –download for Windows 7 and 2008 R2 –built into Windows 8 and 2012 –NetFx 4.0 CLR  Version 4 –download for Windows 7 and 2008 R2, 8 and 2012 –built into Windows 8.1 and 2012 R2 –NetFx 4.5 CLR  Download as Windows Management Framework

Determine version  $psVersionTable  Get-Host  powershell -v 2, powershell -v 3

Script development environment  Notepad  PowerShell ISE  third-party free download –not necessary anymore since Windows 8

Basic language elements  Variables, values and constants –$true, $false, 0x38B, $null –'string', "string", (1..30)  Types (objects vs. structs)  Operators –-eq/-ceq, -ge/-gt, -le/-lt, -like, -clike, -match, -cmatch, -join, -split, -f, -is –-and, -or, -not, !, -xor, -band, -bor, -not, -bxor –*, /, %  Conditions  While, Do While, Foreach, break, continue  Switch  Functions

String and Date methods  [String] –ToLower() –ToUpper() –Split() –Trim()  [DateTime] –AddDays() –Parse()

Object wrappers (adapters)  Get-Member .psbase,.psadapted,.psextended,.psobject –Get-Process, [XML]

Weird access to non-existing members .NonExistentProperty - no efect, empty .NonExistentMethod() - exception  $array[outsideIndex] - exception

Example: COM objects $word = New-Object -ComObject 'Word.Application' $doc = $word.Documents.Add() $range = $doc.Range() $range.Font.Size = 20 $range.Font.Name = 'Verdana' $range.ParagraphFormat.Alignment = 2 $range.Text = 'Hellow world' $docName = 'c:\public\hello.docx' $doc.SaveAs([ref] $docName) $word.Quit()

Example: Static methods and properties  [System.Text.ASCIIEncoding]::ASCII.GetBytes()  [System.Math]::PI  [Math]::Round()  [Convert]::ToBase64String()  [BitConverter]::ToString()

Type accelerators  [ADSI]  [WMICLASS]  [XML]

Custom objects  New-Object PSCustomObject  Add-Member

Weird array 3, 2, 8, 11) -gt (Get-Date), $null, 2, $null, 11) -ne $null

Weir parameter parsing  Parsing in command mode –everything is string except for variables and things in parenthesis –watch out for array goes just with comma separator,  Parsing in expression mode  First token switches the mode: –letter, &,.,. –number, variable, quoted string

Weird default values and conversions  [string] $nothing = $null  [int] $noNumber = $null  [StringBuilder] $noStrBuilder = $null  [int] '55'  '38' * 3  '38' + '95'  95 + '11'  [string] (Get-Process)  Get-Process | fl * | Out-String

Weird collection member functions  PowerShell 3 and newer  If the member does not exist in the collection itself, it gets called on all members

Weird function return values  Whatever goes to pipe in function is returned in array  If you return single-item array it gets converted into a single object  If you return [ArrayList], it converts to [Object[]]

Example: SHA1 $name = 'zkusebni retezec' $nameBytes = [System.Text.ASCIIEncoding]::ASCII.GetBytes($name) $sha = New-Object System.Security.Cryptography.SHA1CryptoServiceProvider $hashBytes = $sha.ComputeHash($nameBytes) # bytes array (20 bytes as SHA-1 is always 160bits) $hashBytes # the same in Base64 [Convert]::ToBase64String($hashBytes) # the same in Hex [BitConverter]::ToString($hashBytes)

C# from PowerShell  Here strings at the end of a line –end as the first character on an empty line Add-Type -TypeDefinition $hereStringDef Add-Type -AssemblyName 'My.Assembly.Name' Add-Type -Path 'c:\projects\myassemblyname.dll' [System.Reflection.Assembly]::LoadFile('…')

Example: Cookie-aware WebClient $typeCookieAwareWebClient namespace Sevecek { public class CookieAwareWebClient : System.Net.WebClient { private System.Net.CookieContainer cookieContainer = new System.Net.CookieContainer(); protected override System.Net.WebRequest GetWebRequest(System.Uri address) { System.Net.WebRequest baseRequest = base.GetWebRequest(address); if (baseRequest is System.Net.HttpWebRequest) { (baseRequest as System.Net.HttpWebRequest).CookieContainer = cookieContainer; } return baseRequest; } if (-not ('Sevecek.CookieAwareWebClient' -as [type])) { Add-Type -TypeDefinition $typeCookieAwareWebClient }

Weird struct assignment $structs namespace Sevecek { public struct subStruct { public string name; public int age; } public struct parentStruct { public string id; public subStruct person; } Add-Type -TypeDefinition $structs $onePerson = New-Object parentStruct $onePerson.person.name = 'ondrej' $onePerson.person

Exception handling try { throw } catch [type] {} finally {} $error -ErrorAction $errorActionPreference throw 'some error' throw (Get-Process)[5]

Win32API with PINVOKE 

Custom CMDLETs in C#  using System.Management.Automation  Class for each cmdlet - decorated as cmdlet  Public properties as parameters - decorated again  Override void processing methods –WriteObject() to pipeline  us/library/dd878294(v=vs.85).aspx

Kurzy Počítačové školy Gopas na GOC171 - Active Directory Troubleshooting GOC172 - Kerberos Troubleshooting GOC173 - Enterprise PKI GOC174 - SharePoint 2013 Troubleshooting GOC175 - Advanced Security GOC169 - Auditing ISO/IEC 2700x Získejte tričko TechEd 2014 za vyplněný hodnotící dotazník. Počítačová škola Gopas – Vaše IT škola života