Simple script to backup CA on a Windows Server
$BackupFolder = "C:\CA_Backup\" $Today = Get-Date -Format MMdd Backup-CARoleService -DatabaseOnly -Path $BackupFolder"$Today"
Short little script that will email you all EventIDs (in this case 7040 and 1501) for the last 24 hours
#List Event IDs that you want monitored $EventId = 7040,1501 #Sepcify time frame, and log file $StartTime = (Get-Date).AddDays(-1) $events = Get-WinEvent -FilterHashtable @{Logname="System"; ID = $EventId; StartTime=$StartTime} #Specify To, From, Subject and email server $EmailFrom = "eventID@alerts.com" $EmailTo = "user@domain.com" $Subject ="Alert From $MachineName" $emailServer = A.B.C.D $result = @() foreach ($A in $events) { $Message = $A.Message $EventID = $A.Id $MachineName = $A.MachineName $Source = $A.ProviderName $result += New-Object psobject -Property @{ EventID = $EventId Source = $Source MachineName = $MachineName Message = $Message } } Send-MailMessage -From $EmailFrom -To $EmailTo -subject $Subject -Body ($result | fl | out-string ) -smtpServer $emailServer -port 25
To connect via PowerShell to office365/Exchange online you need:
Pre-Requisites:
To connect to Exchange Online run:
Connect-ExchangeOnline
and when prompted enter your creds:
To verify:
Below script lists all Windows 10 versions that are installed on computers in Active Directory:
$win10 = get-adcomputer -filter 'OperatingSystem -like "Windows 10*"' -prop * $win10count = ($win10 | Sort OperatingSystemVersion).count $subject = "All Win 10 systems $win10count" $win10_versions = $win10 | Sort OperatingSystemVersion | Select OperatingSystemVersion -unique $result = @() foreach ($ver in $win10_versions) { $version = $ver.OperatingSystemVersion $count = ($win10 | where OperatingSystemVersion -like $ver.OperatingSystemVersion | select OperatingSystemVersion | measure ).count $result += New-Object psobject -Property @{ Win10_version = $version Count = $Count } } Send-MailMessage -From email@address.com -To email@address.com -subject $Subject -Body ($result | out-string) -smtpServer MAIL_SERVER -port 25
Example output:
.\get-Windows10_versions.ps1
Win10_version Count ------------- ----- 10.0 (10240) 1 10.0 (10586) 9 10.0 (14393) 14 10.0 (15063) 4 10.0 (16299) 23 10.0 (17134) 18 10.0 (17763) 21 10.0 (18362) 35 10.0 (18363) 140 10.0 (19041) 1
There are many out-notepad functions out there but for some reason I found them either too long or too complicated so here is mine, short and sweet:
Function Out-Notepad { [CmdletBinding()] Param ( [Parameter(Mandatory=$true, ValueFromPipeline=$true, Position=0)] $StrText ) $fso=new-object -com scripting.filesystemobject $filename=$fso.GetTempName() $tempfile=Join-Path $env:temp $filename $strText | Out-File $tempfile notepad $tempfile #tidy up sleep 3 if (Test-Path $tempfile) {del $tempfile} }