Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. Try
  2. {
  3. $ErrorActionPreference = "Stop";
  4. $WinRMUser = "\`d.T.~Ed/{34846A7C-5BC4-4C23-A22A-D21C1DC99DF8}.{5408AD4E-3052-4F73-B45E-7DADBB999FE4}\`d.T.~Ed/";
  5. $WinRMPass = ConvertTo-SecureString -String "\`d.T.~Ed/{34846A7C-5BC4-4C23-A22A-D21C1DC99DF8}.{98301C29-F4AF-4A43-88D3-851520744C6B}\`d.T.~Ed/" -AsPlainText -Force;
  6. $Credential = New-Object System.Management.Automation.PSCredential ($WinRMUser, $WinRMPass);
  7. #
  8. # We will connect to and run powershell from the local orchestrator server
  9. #
  10. $ComputerName = "\`d.T.~Ed/{34846A7C-5BC4-4C23-A22A-D21C1DC99DF8}.{B0699ECA-EA8F-40B6-A73F-00D220D955C6}\`d.T.~Ed/";
  11. #
  12. # Pass these into invoke
  13. #
  14. $AdsPath = "\`d.T.~Ed/{34846A7C-5BC4-4C23-A22A-D21C1DC99DF8}.{332FD283-912F-431C-A481-26433B5FB78D}\`d.T.~Ed/";
  15. $SearchFilter = "\`d.T.~Ed/{34846A7C-5BC4-4C23-A22A-D21C1DC99DF8}.{401BF2E1-D1CF-4650-A9D4-22E6955B547F}\`d.T.~Ed/";
  16. #
  17. # The following two modules are my custom modules for working with AD and text logfiles
  18. #
  19. $LogModulePath = "\`d.T.~Ed/{34846A7C-5BC4-4C23-A22A-D21C1DC99DF8}.{C230740F-832C-44D8-A496-D4BBD86018B0}\`d.T.~Ed/";
  20. $ADModulePath = "\`d.T.~Ed/{34846A7C-5BC4-4C23-A22A-D21C1DC99DF8}.{2652BC51-9A85-45C3-ADD8-8A9FF7FB92E7}\`d.T.~Ed/";
  21. #
  22. # Set this to be the location of your logfiles, if you leave it blank the functions will create C:\Logfiles and store them there
  23. #
  24. $LogPath = "\`d.T.~Ed/{34846A7C-5BC4-4C23-A22A-D21C1DC99DF8}.{2563F269-803F-4855-A3D2-198BCDDEEB07}\`d.T.~Ed/";
  25. #
  26. # A descriptive name that will become the logfile
  27. #
  28. $LogName = "";
  29. #
  30. # Add whatever variablese you need here
  31. #
  32. New-EventLog -LogName "Windows PowerShell" -Source $LogName -ErrorAction SilentlyContinue
  33. $Session = New-PSSession -ComputerName $ComputerName -Credential $Credential -Authentication Credssp
  34. #
  35. # Whatever additional variables you add above, make sure to add them to the argumentlist below
  36. #
  37. Invoke-Command -Session $Session -ArgumentList $AdsPath, $SearchFilter, $LogModulePath, $ADModulePath, $LogPath, $LogName -ScriptBlock
  38. {
  39. #
  40. # Param == Argumentlist check your work here
  41. #
  42. Param ($AdsPath, $SearchFilter, $LogModulePath, $ADModulePath, $LogPath, $LogName)
  43. try
  44. {
  45. Import-Module $LogModulePath;
  46. Import-Module $ADModulePath;
  47. #
  48. # Import any other required modules here
  49. #
  50. #
  51. # Start the work
  52. #
  53. Write-LogFile -LogPath $LogPath -LogName $LogName -Source "Execution" -EventID 100 -EntryType "Information" -Message "Begin Office 365 Provisioning";
  54. #
  55. # End the work
  56. #
  57. Write-LogFile -LogPath $LogPath -LogName $LogName -Source "Execution" -EventID 100 -EntryType "Information" -Message "End Office 365 Provisioning";
  58. }
  59. catch
  60. {
  61. #
  62. # This catch handles any errors that may occur inside the session
  63. #
  64. Write-EventLog -LogName 'Windows PowerShell' -EntryType Error -Source $LogName -EventId 2 -Message $Error[0].Exception;
  65. }
  66. }
  67. }
  68. catch
  69. {
  70. #
  71. # You may need to hardcode your logname here, this catch handles any connection errors that may occur
  72. #
  73. Write-EventLog -LogName 'Windows PowerShell' -EntryType Error -Source $LogName -EventId 1 -Message $Error[0].Exception;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement