Powershell basic tasks

Powershell drives

31/10/2012 21:32
  PS> Get-PSDrive Name Provider Root ...

Get the name or location of current script and parent path

15/10/2012 15:49
#full name $Myinvocation.invocationname #path $myinvocation.InvocationName |...

Get file path and file name from full file name

15/10/2012 15:32
$path = "c:\temp\filename.txt" split-path $path returns...

Skip foreach item and suppress output

13/10/2012 21:20
   $a=(1, 2, 5, 6, 4, 1, 5) foreach($item in $a) {  ...

Create menu item in Powershell ISE

13/10/2012 05:28
  #IItem is added to 'Add-ons' menu in Powershell ISE #it is there...

Break command

13/10/2012 02:34
#break script, I needed it for validation   #break...

Create profile in Powershell ISE

12/10/2012 21:11

Return in function with param

12/10/2012 21:07
  function hadajCislo { param([int]$cislo)     if($cislo...
<< 1 | 2 | 3


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))    ...


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...