Saturday 22 December 2012

Show-Exceptions.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script gets all the exceptions you can trap by PowerShell 
  4. .DESCRIPTION 
  5.     This script looks at all the loaded assemblies to get all 
  6.     the exceptions you can trap/catch using PowerShell. The 
  7.     display only covers those parts of the .NET framework are loaded. 
  8. .NOTES 
  9.     File Name  : Show-Exceptions.ps1 
  10.     Author     : Thomas Lee - tfl@psp.co.uk 
  11.     Requires   : PowerShell Version 2.0 
  12. .LINK 
  13.     This script posted to: 
  14.         http://www.pshscripts.blogspot.com 
  15. .EXAMPLE 
  16.     Psh> .\Show-Exceptions.ps1 -Summary 
  17.     In 69 loaded assemblies, you have 418 exceptions: 
  18.  
  19. .EXAMPLE 
  20.     Psh> .\Show-Exceptions.ps1 
  21.     In 69 loaded assemblies, you have 418 exceptions: 
  22.  
  23.     Name                     FullName                                                 
  24.     ----                     --------                                                 
  25.     _Exception               System.Runtime.InteropServices._Exception                
  26.     AbandonedMutexException  System.Threading.AbandonedMutexException                 
  27.     AccessViolationException System.AccessViolationException                      
  28.     ... 
  29.      
  30. #> 
  31.  
  32. [CMDLETBINDING()] 
  33. Param ( 
  34. [switch] $summary 
  35. #    Get all the exceptions 
  36. $assemblies = [System.AppDomain]::CurrentDomain.GetAssemblies() 
  37. $exceptions = $Assemblies | ForEach { 
  38.      $_.GetTypes() | where { $_.FullName -Match "System$filter.*Exception$" } } 
  39.  
  40. # Now display the numbers checking for summary flag 
  41. "In {0} loaded assemblies, you have {1} exceptions:" -f $assemblies.count, $exceptions.count 
  42. If (-not $summary) { 
  43. $Exceptions | sort name | format-table name, fullname 
Technorati Tags:

Sunday 9 December 2012

Get-LyncAutoLogonStatus.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script reports on whether Lync should 
  4.     automatically start on a machine when a user 
  5.     logs in
  6. .DESCRIPTION 
  7.     This script looks in the registry at a chosen machine 
  8.     to determine if the Lync client should automatically 
  9.     attempt to login when a user logs onto that system. 
  10. .NOTES 
  11.     File Name  : Get-LyncAutoLogonStatus 
  12.     Author     : Thomas Lee - tfl@psp.co.uk 
  13.     Requires   : PowerShell Version 2.0 
  14.                  Lync 2010 or later 
  15. .LINK 
  16.     This script posted to: 
  17.         http://www.pshscripts.blogspot.com 
  18. .EXAMPLE 
  19.     Psh> .\Get-LyncAutoLogonStatus     
  20.     Automatically start Lync when I log on to Windows: True 
  21. #> 
  22.  
  23.  
  24. [Cmdletbinding()] 
  25. Param ( 
  26. [string] $computer = "Cookham8.Cookham.net"
  27.  
  28.  
  29. # Get the relevant registry key 
  30. $registry = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("CurrentUser", $computer
  31. $key = $registry.OpenSubKey("SOFTWARE\Microsoft\Communicator", $True
  32.   
  33. # now write to host the details 
  34. Write-Host "Automatically start Lync when I log on to Windows:",` 
  35.     ([boolean] $key.GetValue("AutoRunWhenLogonToWindows",$null)) 
Technorati Tags: ,

Sunday 2 December 2012

Set-AdminLogon.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script defines a function that sets autologon 
  4. .DESCRIPTION 
  5.     Autologon enables the system to logon after a reboot without 
  6.     you needing to enter credentials. This is an ideal scenario 
  7.     for lab or training room systems. This script defines 
  8.     a function that sets a userid/password and autologon.
  9. .NOTES 
  10.     File Name  : Set-AdminLogon 
  11.     Author     : Thomas Lee - tfl@psp.co.uk 
  12.     Requires   : PowerShell Version 2.0 
  13. .LINK 
  14.     This script posted to: 
  15.         http://www.pshscripts.blogspot.com 
  16. .EXAMPLE 
  17.     Psh> New-AdminLogon -user cookham\tfl -password 'JerryGarciaR0cks!' 
  18.     Auto logon created for [Cookham\tfl] with password: [JerryGarciaR0cks]          
  19.  
  20. #> 
  21.  
  22. Function New-AdminLogon { 
  23.  
  24. [cmdletbinding()] 
  25. Param( 
  26. [string] $User     = $(Throw 'No user id specified'), 
  27. [string] $Password = $(Throw 'No password specified'
  28.  
  29. # Define registry path for autologon 
  30. $RegPath = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' 
  31.  
  32. # Set autologon 
  33. Set-ItemProperty -Path $RegPath -Name AutoAdminLogon -Value 1  
  34.  
  35. # Set userid and password 
  36. Set-ItemProperty -Path $RegPath -Name DefaultUserName -Value $User  
  37. Set-ItemProperty -Path $regPath -Name DefaultPassword -Value $Password  
  38.  
  39. # Say nice things and exit! 
  40. Write-Host ("Auto logon [{0}] set to password: [{1}]" -f $user, $password
  41.  
  42. Set-AdminLogon -User 'Cookham\tfl' -Password 'JerryGarciaR0cks' 
Technorati Tags: ,

Remove-AdminLogon.ps1

  1. <#
  2. .SYNOPSIS
  3. This script defines a function that removes autologon
  4. .DESCRIPTION
  5. Autologon enables the system to logon after a reboot without
  6. you needing to enter credentials. This is an ideal scenario
  7. for lab or training room systems. This script defines
  8. a function that removes the autologon registry keys
  9. .NOTES
  10. File Name : Remove-AdminLogon
  11. Author : Thomas Lee - tfl@psp.co.uk
  12. Requires : PowerShell Version 2.0
  13. .LINK
  14. This script posted to:
  15. http://www.pshscripts.blogspot.com
  16. .EXAMPLE
  17. Psh> Remove-AdminLogon
  18. Auto logon settings removed
  19. #>
  20. Function Remove-AdminLogon {
  21. [Cmdletbinding()]
  22. Param()
  23. # Define registry path for autologon
  24. $RegPath = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon'
  25. # Remove autologon property
  26. Remove-ItemProperty -Path $RegPath -Name AutoAdminLogon
  27. # Remove userid and password
  28. Remove-ItemProperty -Path $RegPath -Name DefaultUserName
  29. Remove-ItemProperty -Path $RegPath -Name DefaultPassword
  30. # Say nice things and exit!
  31. Write-Host ("Auto logon removed")
  32. }
  33. Remove-AdminLogon
Technorati Tags: ,

New-AutoAdminLogon.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script defines a function that sets autologon 
  4. .DESCRIPTION 
  5.     Autologon enables the system to logon after a reboot without 
  6.     you needing to enter credentials. This is an ideal scenario 
  7.     for lab or training room systems. This script defines 
  8.     a function that sets a userid/password and autologon. It does NOT 
  9.     check to see if the value entries already exist. 
  10. .NOTES 
  11.     File Name  : Set-AutoAdminLogon 
  12.     Author     : Thomas Lee - tfl@psp.co.uk 
  13.     Requires   : PowerShell Version 2.0 
  14. .LINK 
  15.     This script posted to: 
  16.         http://www.pshscripts.blogspot.com 
  17. .EXAMPLE 
  18.     Psh> Set-AutoAdminLogon -user cookham\tfl -password 'JerryGarciaR0cks!' 
  19.     Auto logon set for [Cookham\tfl] with password: [JerryGarciaR0cks]          
  20.  
  21. #> 
  22.  
  23. Function Set-AdminLogon { 
  24.  
  25. [cmdletbinding()] 
  26. Param( 
  27. [string] $User     = $(Throw 'No user id specified'), 
  28. [string] $Password = $(Throw 'No password specified'
  29.  
  30. # Define registry path for autologon 
  31. $RegPath = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' 
  32.  
  33. # Set autologon 
  34. New-ItemProperty -Path $RegPath -Name AutoAdminLogon -Value 1 -EA 0 
  35.  
  36. # Set userid and password 
  37. New-ItemProperty -Path $RegPath -Name DefaultUserName -Value $User -EA 0 
  38. New-ItemProperty -Path $regPath -Name DefaultPassword -Value $Password -EA 0 
  39.  
  40. # Say nice things and exit! 
  41. Write-Host ("Auto logon set for [{0}] with password: [{1}]" -f $user, $password
  42.  
  43. Set-AdminLogon -User 'Cookham\tfl' -Password 'JerryGarciaR0cks' 
Technorati Tags: ,