SHIFT

--- Sjoerd Hooft's InFormation Technology ---

User Tools

Site Tools


adcontrols
Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
adcontrols [2019/02/08 15:08]
sjoerd
adcontrols [2019/02/14 14:03] (current)
sjoerd [Check Local Admin Access on Servers]
Line 14: Line 14:
 Scripts can be scheduled from any Windows Server but it needs domain admin permissions to access all local servers. The scripts are located on a central Script Repository so you need to set the executionpolicy accordingly:​ Scripts can be scheduled from any Windows Server but it needs domain admin permissions to access all local servers. The scripts are located on a central Script Repository so you need to set the executionpolicy accordingly:​
  
-* Program: C:​\Windows\System32\WindowsPowerShell\v1.0\powershell.exe+* PowerShell:​ 
 +** Program: C:​\Windows\System32\WindowsPowerShell\v1.0\powershell.exe 
 +* PowerShell Core (version 6 and higher): 
 +** Program: C:\Program Files\PowerShell\6\pwsh.exe
 * Arguments: ​ * Arguments: ​
  
Line 37: Line 40:
 # Changed email format to HTML # Changed email format to HTML
 ###  ​ ###  ​
 +### 2019 02 14 ###
 +# Added script to check for server availability
 +# Made some changes to the Send-Email Function for high priority emails and emails without attachments ​
 ###################################################################################################​ ###################################################################################################​
  
Line 46: Line 52:
 ### All other variables need to be set in the script ### All other variables need to be set in the script
 Function Send-Email ($subject, $info){ Function Send-Email ($subject, $info){
-   ​Send-MailMessage -To $toemail -From $fromemail -cc $ccmail -SmtpServer $mailserver -Subject $subject -Body $info -BodyAsHtml -Attachments "​$monthreport"​+   # Send high prio email without attachment 
 +   if ($priority -eq "​high"​ -and $monthreport -eq $null){ 
 + Send-MailMessage -To $toemail -From $fromemail -cc $ccmail -SmtpServer $mailserver -Subject $subject -Body $info -BodyAsHtml -Priority High 
 +   } 
 +   # Send mail without attachment (some Controls do not need attachments)  
 +   ​elseif ($monthreport -eq $null){ 
 + Send-MailMessage -To $toemail -From $fromemail -cc $ccmail -SmtpServer $mailserver -Subject $subject -Body $info -BodyAsHtml 
 +
 + else{ 
 + Send-MailMessage -To $toemail -From $fromemail -cc $ccmail -SmtpServer $mailserver -Subject $subject -Body $info -BodyAsHtml -Attachments "​$monthreport"​ 
 + }
 } }
 ### End  ### End 
 ### ###
 +### Check if server is available
 +### Needs one parameter ​
 +#### $computername : servername in [string] format
 +Function CheckAvailability($computername){
 + #​$computername = $computer.Name
 + if (Test-Connection $computername -quiet -count 1){
 + # Computer answers to ping
 + #​powershell 6 does not support this anymore: https://​docs.microsoft.com/​en-us/​powershell/​scripting/​whats-new/​breaking-changes-ps6?​view=powershell-6
 + if ($PSVersionTable.PSVersion.Major -eq 6){
 + Return "​OK"​}
 + elseif (get-wmiobject -ErrorAction SilentlyContinue -computername $computername "​win32_process"​){
 + #​Computer reageert op wmi
 + Return "​OK"​}
 + else{Return "​WMIError"​}}
 + else{Return "​PingError"​}
 +}
 +### End
 +### 
 ### Upload file to SharePoint ### Upload file to SharePoint
 ### No parameters ### No parameters
Line 609: Line 643:
 ####### If this changed since last time the script ran it does not show the current accounts but the changes ####### If this changed since last time the script ran it does not show the current accounts but the changes
 ### ###
-### 20190 02 05 - Sjoerd Hooft ###+### 2019 02 05 - Sjoerd Hooft ###
 # Added HTML email as output with all TOPdesk changes in email  # Added HTML email as output with all TOPdesk changes in email 
 # Added ICT CF information to email  # Added ICT CF information to email 
 # Added clearity for username and password for both SharePoint and SQL # Added clearity for username and password for both SharePoint and SQL
 +### 2019 02 14 - Sjoerd Hooft ###
 +# Moved CheckAvailability Function to common functions script ​
 ###################################################################################################​ ###################################################################################################​
  
Line 753: Line 789:
  
 ### Other Functions ### Other Functions
-Function CheckAvailability($computername){ +### Moved to Functions script 
- #​$computername = $computer.Name +#Function CheckAvailability($computername){ 
- if (Test-Connection $computername -quiet -count 1){ +# #​$computername = $computer.Name 
- # Computer answers to ping +# if (Test-Connection $computername -quiet -count 1){ 
- if (get-wmiobject -ErrorAction SilentlyContinue -computername $computername "​win32_process"​){ +# # Computer answers to ping 
- #​Computer reageert op wmi +# if (get-wmiobject -ErrorAction SilentlyContinue -computername $computername "​win32_process"​){ 
- Return "​OK"​} +# #Computer reageert op wmi 
- else{Return "​WMIError"​}} +# Return "​OK"​} 
- else{Return "​PingError"​} +# else{Return "​WMIError"​}} 
-}+# else{Return "​PingError"​} 
 +#}
  
 Function GroupNesting($groupmembers){ Function GroupNesting($groupmembers){
adcontrols.1549634904.txt.gz · Last modified: 2019/02/08 15:08 by sjoerd