Powershell basic tasks

Join arrays together

12/01/2013 12:50
#Joining arrays in powershell, use + operator $a=(1,2,3) $b=(4,5,6,7) $c=($a,...

Create powrshell variables in a loop

12/01/2013 01:13
#Create variables with specific names in a loop #Create variables...

Include the same setting file only once

17/12/2012 11:18
We have many scripts (e. g. debug.ps1, debug2.ps1) with one shared...

Case sensitive comparison in powershell

07/12/2012 15:20
case sensitive comparison   $item=$node|where-object {$_.Title...

Remove Illegal characters from filename

16/11/2012 17:13
$file = "this*file\\i?.txt" $file $pattern = "[{0}]" -f...

Create an instance of object in powershell

14/11/2012 08:46
#in csharp it is: using...

Get Powershell version

12/11/2012 08:50
$host #or $host.Version #or $PSVersionTable Name Value ----...

Create certificate using SelfSSL7 tool

02/11/2012 10:41
#Create Certificate - use SelfSSL7 tool #input parameters:...

Add registry DWORD value

02/11/2012 09:50
#you can go to the psdrive directly, but don't need set-location hklm: #for...

Get and set folder permission, powershell elevated privileges

01/11/2012 03:10
get-acl -path $webConfigPath #Equivalent of elevated privileges in...
<< 1 | 2 | 3 >>

Notes

Catch exception

12/10/2012 18:28
#save previous setting $defaultErrorAction=$ErrorActionPreference #Force program to catch exception in case of error $ErrorActionPreference="Stop" try { #use some method with specified exception     $item=$WorkItemStore.GetWorkItem(20156) } catch...

Ternary operator

06/08/2012 19:00
First run following definition      filter Invoke-Ternary ([scriptblock]  $decider,[scriptblock]$iftrue,[scriptblock]$iffalse)  {  if (&$decider) { &$iftrue} else { &$iffalse }  }   Then set alias for...

Apply function against an array

14/01/2012 00:10
function vypisParametrov {     param(         [string]$url,         [string]$nodeUrl,         [string]$nodeName     )     write-host "On...

Get site url from library url

13/01/2012 23:16
Get site url from library url    $libraryUrl="https://td_sp_ui/sites/test/CategoryCards/Pages"     #take site url from library url (one level folder)     $siteUrl=$libraryUrl.substring(0, $libraryUrl.LastIndexOf("/"));    ...

Remove, Add and Deploy solution

11/01/2012 14:15
Basic task against solution   List of solutions get-spsolution   If is deployed, uninstall it Uninstall-spsolution solutiionName.wsp -webapplication https://tdspui Remove-spsolution solutionName.wsp   Add new solution Add-SPSolution...

Get server and site name from url

09/01/2012 21:53
function GetServerNameFromUrl(     [string]$url ) { $server=$url.split("/") return $server[2] } function GetServerFromUrl(     [string]$url ) { $first=$url.IndexOf('/') $short=$url.substring($first+2,$url.length-$first-2) $server=$url.substring(0,...

pozn. k nastaveniu stylu stranky

07/01/2012 01:40
V .css file som zmenil nastavenie p  margin-botom na 0em pri #mainContent box_content p  line-height z 1.8em na 1.2em.

Feed choice menu with options

07/01/2012 01:36
#Feed choice menu with options. function SelectChoice {         param(         [array]$options         ) if(($options.length -gt 1))    ...

Others

Convert .cer file to .pfx

22/05/2018 12:12
There is cool article on https://blog.jayway.com/2014/09/03/creating-self-signed-certificates-with-makecert-exe-for-development/ how to make self signed certificate using makecert and pvk2pfx commands. But for access pvk2pxf you will need to instal Windows Driver Kit or some extensions...