CA Service Management

pdm_webstat PowerShell script for AA architecture 

Jun 17, 2016 02:08 PM

pdm_webstat usage example in AA environment

The following is a simple PowerShell script I wrote which will write the pdm_webstat output from all servers in your environment into a single text file and optionally send it as an attachment via email.

 

Notes:

  • I've only used this in a domain environment where I have admin privileges on all the service desk servers.
  • The Send-MailMessage command is structured assuming there is an unsecured SMTP server available
  • icm is an alias for Invoke-Command PowerShell command
  • cn is short for the computer name flag
  • $app_srvrs is an array containing the fully qualified domain names for all app servers in the environment
  • Each entry in the $app_srvrs array is set to the $srvr variable as it's run in the ForEach loop

 

Using the script:

  • Set each appx_fqdn entry to the appropriate server FQDNs in your environment, you can add/remove additional servers onto the array
  • Set the <output_location> to a location on the background server or an open share in the environment
  • webstat_$(get-date -f yyyy-MM-dd-hhtt).txt is the filename used to concatenate the pdm_webstat results, the $(get-date -f yyyy-MM-dd-hhtt) variable appends the time stamp onto the filename
  • To enable the send-mailmessage command remove the comment blocks and set an appropriate SMTP server for your environment and update the recipients/from addresses

 

PowerShell script (also attached to document):

$app_srvrs = @("app1_fqdn","app2_fqdn","app3_fqdn","app4_fqdn","app5_fqdn")
 #Start all jobs
ForEach($srvr in $app_srvrs)
{
  $srvr | out-file "<output_location>\webstat_$(get-date -f yyyy-MM-dd-hhtt).txt" -append
    icm -cn $srvr -ScriptBlock { pdm_webstat } | out-file "<output_location>\webstat_$(get-date -f yyyy-MM-dd-hhtt).txt" -append
}
<###########
Send-MailMessage -Subject "Service Desk Manager Web Statistics" -To user1@test.com,user2@test.com -From servicedeskmanager.noreply@test.com -Body "Service Desk Manager web statistics report attached to email. Files saved to <a href=file:///<output_location>\webstats/>here</a>" -BodyAsHtml -SmtpServer <smtp_server> -Attachments "<output_location>\webstat_$(get-date -f yyyy-MM-dd-hhtt).txt"
############>
Exit

 

Creating a scheduled task to execute the script:

The following shows how to create a repeating task that is executed every hour.  You can adjust this to your needs.

  • Task Trigger

  • Task Action and Argument

  • Argument: -ExecutionPolicy Bypass D:\scripts\Webstat_Email_Task.ps1

Statistics
0 Favorited
2 Views
1 Files
0 Shares
1 Downloads
Attachment(s)
zip file
Webstat_Email_Task.ps1.zip   550 B   1 version
Uploaded - May 29, 2019

Related Entries and Links

No Related Resource entered.