16 January 2017

Keyboard shortcuts for Powershell console

Ctrl + End - delete all text after the cursor
Ctrl + Home - delete all text before the cursor

29 December 2016

Dispose COM objects as it can cause memory leaks

# dispose COM objects as it can cause memory leaks
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($VariableName) | Out-Null

15 December 2016

Calculate MD5 with powershell


[Reflection.Assembly]::LoadWithPartialName("System.Web")
[System.Web.Security.FormsAuthentication]::HashPasswordForStoringInConfigFile("p@ssw0rd", "MD5")

08 December 2016

Display a MessageBox from PowerShell


[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
[System.Windows.Forms.MessageBox]::Show("Hello there !")
[System.Windows.Forms.MessageBox]::Show("Hello there !", "Some title")


you can also have buttons like:

0: OK
1: OK Cancel
2: Abort Retry Ignore
3: Yes No Cancel
4: Yes No
5: Retry Cancel

[System.Windows.Forms.MessageBox]::Show("Hello there !", "Some title", 4)



you can olso read the unswer from the user:

$Unswer = [System.Windows.Forms.MessageBox]::Show("Hello there !", "Some title", 4)
if ($Unswer -eq "YES" ) { # perform sone task }
else { # perform some other task}

more info on msdn

20 October 2016

Grant sharing permissions for multiple users with net share

net share sharename=path_to_folder /GRANT:username,FULL /GRANT:username2,FULL