You are on page 1of 3

Risk mitigation parametres

Get-Alias -Definition Stop-Service

$scriptblock = {Get-ChildItem C:\}

&$scriptblock
$scriptblock.Invoke()
$scriptblock.Invoke will show method definition

Rename pipeline object name:

Get-ChildItem C:\LabFiles -PipelineVariable FileObject | Where-Object


{$FileObject.name -like "*"}

Modifica executionpolicy pentru instanta curenta de powershell

Set-ExecutionPolicy -Scope Process RemoteSigned

NTFS stream zone file

$array =1,2,3,4,5,

$array[1,3,-1]

$array[1..3]

(10..35) .GetType()

Arraylist collections are much faster than a (fixed) array

$al = New-Object System.Collections.ArrayList


$al.Add(1)
$al.Add(234)

When you extend an array the computer copy the hole content of the array and create a new one to
which adds the new element

To get the memebers of the array object and not the one of the array memebrs:

Get-Member InputObject $array


$dirs = @(c:\users,c:\windows)

Invole-Command Computername comp1, comp2 ScriptBlock { $using:dirs | %{ [pscutomobject]@{


Path = $_ ; Exist = $_ | Test-Path } }}

Regular expression:

search for: regular expression language elements

https://msdn.microsoft.com/en-us/library/az24scfc(v=vs.110).aspx

output stream main stream 0 zero

error stream 2 red color by default execution problem

warning stream 3

Debug

Console debug full debug capabilities.

Set-PSBreackPoint for cmdlets, variable , functions, ..etc.

Help in debug mode: use h or ? for help

$PSCommandPath for powershell 3 sau mai mare.

Trace-Command -PSHost -Name parameterbinding -Expression {Get-Process powershell}

Get-TraceSource

$code = @"
public class testclass{
public static string GetData(){
return "my text ";
}
}

"@

Add-Type -TypeDefinition $code # -ReferencedAssemblies # if some GAC are used in the


code block - EX: using System
[testclass]::GetData()
For really big text files :

Get-Content filepath file path Raw

Will load in a few seconds but will have only one string in it.

[System.IO.File]::ReadFile / readall text #load file with dotnet clases an methods

Desire State Configuration

Declarative language
Desired final state of the computer
doesnt need a domain to work
doesnt need network connectivity
Requires OS v4.0 v5.0 is recomanded
requires remoting

Optional pull server: IIS or File Share

Buld DSC Configuration


generate MOF File
Apply DSC Resource to machine: Start-DscConfiguration

Get-DscResource
Get-DscResource -Name File -Syntax

You might also like