Mostrando entradas con la etiqueta powershell. Mostrar todas las entradas
Mostrando entradas con la etiqueta powershell. Mostrar todas las entradas

lunes, 15 de diciembre de 2014

How Get Events of Task Scheduler using Powershell

Hi script guys!

For today I have a simple script to collect events of task scheduler.
It is very easy and I think practice some times, because we can have several tasks scheduled in a system and review if they are working fine it is not funny .... :-(

enjoy it!!!


<# =======================================================================

File Name: GetEventsTaskScheduler_v01.ps1

Author: citrixpedia@gmail.com
Date: 9-dic-2014

Comments: Script to get all events of task scheduler and outpu to text file


======================================================================= #>


#-------------------------------------

# Get Location of script
#-------------------------------------

Get-Location | ForEach-Object { $myPath = $_.Path }


$outputfile= $myPath + "\EventsTaskSchedule.log"


#-------------------------------------

# Get Events
#-------------------------------------

get-winevent -LogName 'Microsoft-Windows-TaskScheduler/Operational' | Where-Object { $_.LevelDisplayName -match "Error" } | fl LevelDisplayName, TimeCreated, OpcodeDisplayName, TaskDisplayName, MachineName, Message | Out-File -Encoding ascii $outputfile


Checking with Powershell if Citrix XenApp 7.6 Services are running

Hi Citrix guys.

This time only I have a simple script to check if all citrix services are runing.
If some service is Stopped, restart again and send an email to report.

Das ist nicht Cool

<# =======================================================================

File Name: CheckCitrixMonitoring_v01.ps1

Author: citrixpedia@gmail.com

Comments: Script developed to check citrix monitoring services. if the services is stopped, it will be started and it will send an email.


======================================================================= #>


$LogFileName="$env:TEMP\CheckCitrixMonitoring.log"

$smtpServer="<smtp_server_fqdn>"
$smtpFrom="<sender_address>"
$smtpAddress="<recipiente_address>"

$eventSource="Citrix Monitoring"

$eventID=7601

#-------------------------------------

# create body message
#-------------------------------------

$header = "The following services were stopped and it has proceeded to start them again.`nPlease, check them: "

$footer= "Please, notify to: $smtpAddress about this message."

#------------------------------

# write event in the system
#------------------------------

New-EventLog -LogName System -Source $eventSource


#-------------------------------------

# Check Citrix Services and if the service is stopped, restart again and send mail to report
#-------------------------------------


$stoppedServices=Get-Service | Where-Object {$_.DisplayName -like "*Citrix*"} | Where-Object {$_.Status -eq "Stopped"} | fl display*,status

$stoppedServices | Out-File -Encoding ASCII $LogFileName

if ($stoppedServices) {

    $readFile=Get-Content -Encoding ASCII $LogFileName
    Get-Service | Where-Object {$_.DisplayName -like "*Citrix*"} | Where-Object {$_.Status -eq "Stopped"}| Start-Service
    Write-EventLog -LogName System -Source $eventSource -EventId $eventID "Warning" –Message "`n$header`n`n$readFile`n`n$footer"

    Send-mailmessage -SmtpServer $smtpServer -from $smtpFrom -to $smtpAddress1 -Subject "Citrix Monitoring Alert -> $env:COMPUTERNAME" -body "`n$header`n`n$readFile`n`n" -Attachments $LogFileName


}




How Export all Citrix XenApp 7.6 apps in a CSV file

An option could be get all information about XenApp 7.6 Site and exporting each Delivery Group.
To acomplish this firstly it is necessary get all delivery groups and late, using the attributte UUID, connect to each delivery Group to get all applications inside this group.

If you thinsk you can improove this script, please, send me your improovements to this mail: citrixpedia@gmail.com 

thanks and enjoy it!!

<# =======================================================================

File Name: ExportDeliveryGroupApps_v01.ps1

Author: citrixpedia@gmail.com
Date: 25-nov-2014

Comments: Script developed to get all apps information for each Delivery Group and dump this info in a different csv file.


======================================================================= #>


#-------------------------------------

# Get Location of script
#-------------------------------------

Get-pssnapin -registered | add-pssnapin -passthru


Get-Location | ForEach-Object { $myPath = $_.Path }

$myDate = Get-Date -UFormat "%Y-%m-%d %H%M"

#--------------------------------------------------------------------------------------------------

# Create a "....DeliveryGroups.csv" file with a list of all delivery groups and users permissions
#--------------------------------------------------------------------------------------------------

$myFileName = $myPath + "\" + $myDate + "_DeliveryGroups.csv"

$header = "DeliveryName;UUId;ColorDepth;Enabled;NumPublishedApplications;IncludedUsers"
$header | Out-File $myFileName -encoding ASCII 

Get-BrokerDesktopGroup | Where-Object {$_.Enabled -eq "True"} | ForEach-Object { 

if ($_.Name) { $myDesktopGroupName = $_.Name }
$myString = $_.Name + ";" + $_.UUId + ";" + $_.ColorDepth + ";" + $_.Enabled + ";" + $_.TotalApplications

#--------------------------------------------------------------------------------------------------

#   Get-BrokerAccessPolicyRule -> this CMDLET permits get access permissions
#--------------------------------------------------------------------------------------------------
Get-BrokerAccessPolicyRule | Where-Object { $_.uid -eq "1" -and $_.DesktopGroupName -eq $myDesktopGroupName } | ForEach-Object { 
if ($_.IncludedUsers) { $myIncludedUsers = $_.IncludedUsers }
}
$myUsers = ""
$myIncludedUsers | ForEach-Object {
if ($_.Name -and $myUsers) {$myUsers = $myUsers + "," + $_.Name}
elseif ($_.Name -and -not $myUsers) {$myUsers = $_.Name}
}
$myString + ";" + $myUsers | Add-Content $myFileName
}

#----------------------------------------------------------------------------------------------------------------

# Create a "....<delivery_group_name>_DeliveryGroupApps.csv" file with a list of all apps for each delivery group
# UUID is the attribute to identify and link apps and delivery groups
#----------------------------------------------------------------------------------------------------------------

Get-BrokerDesktopGroup | Where-Object {$_.Enabled -eq "True"} | ForEach-Object { 

$myUUID= $_.UUID
$myFileName = $myPath + "\" + $myDate + "_" + $_.name + "_DeliveryGroupApps.csv"
$myHeader = "AdminFolderName;ApplicationName;ApplicationType;DisplayName;ClientFolder;CommandLineArguments;CommandLineExecutable;AppName;PublishedName;Visible;WaitForPrinterCreation;WorkingDirectory"
$myHeader | Out-File $myFileName -encoding ASCII 

$apps = Get-BrokerApplication -SortBy Name | Where-Object { $_.AssociatedDesktopGroupUUIDs -eq $myUUID }


Foreach ($app in $apps) {
$myString = $app.AdminFolderName + ";" + $app.ApplicationName + ";" + $app.ApplicationType + ";" + $app.BrowserName + ";" + $app.ClientFolder + ";" + $app.CommandLineArguments + ";" + $app.CommandLineExecutable + ";" + $app.Name + ";" + $app.PublishedName + ";" + $app.Visible + ";" + $app.WaitForPrinterCreation + ";" + $app.WorkingDirectory
$myString | Add-Content $myFileName
}
}