Send email using content of a text file - vba

I'm hope to create a script which looks up a date in a text file and then send an email to the corresponding email address. The text file would be structured something like this:
25/02/2018, blah#email.com
26/02/2018, blue#email.com
etc
This will be run on a Windows 2012 box so ideally i'd like to use powershell. I don't want any reliance on a database so i thought a simple text file that could be searched may be the easiest way. Essentially this will be used to send emails alerts for for certain events with the date being used to sent the email to the correct night duty staff. Need to use a script as some of the apps that I hope to link it to have little to no notification options but they can invoke external scripts.
Any guidance gratefully received.
Thanks,
A

Your question is quite broad; here's the outline of a solution (run as a script file, PSv3+):
# Declare a parameter for the target date.
param(
[datetime] $TargetDate = [datetime]::Today
)
# Format the target date as a string to match the input file's date format.
$targetDateFormatted = (Get-Date -Date $TargetDate -Format 'dd/MM/yyyy')
# Specify the input file (CSV format, as implied by your sample data).
$inputFile = 'DateEmail.csv'
Import-Csv -Header Date, Email $inputFile |
Where-Object Date -eq $targetDateFormatted |
ForEach-Object {
Write-Verbose -Verbose "Date is $($_.Date); email address is $($_.Email)"
# Invoke the Send-MailMessage cmdlet here.
}

Related

Checking availability of a large amount of applications in Microsoft store

My goal is to check for around 800 tools whether they are available in the Microsoft Store or not. Is there a way to query the tools available in the Microsoft Store via API or something similar?
I am grateful for any suggestions. Thank you
I recommend to use a scripting language like PowerShell or BASH or pick your favorite to automate your 800 queries of the Microsoft Store web interface with the respective query at the following URI in the PowerShell example:
$region = 'en-us' # Variable to represent your region.
$keywords = 'Hello+World' # Tool name here, keywords separated by plus
$query = 'https://www.microsoft.com/{0}/search/explore?q={1}' -f $region,
$keywords
$response = Invoke-WebRequest -Uri $query
# Parse the response HTML, e.g. $response.Links | Out-Gridview
Cheers,
CarnegieJ

Change in the HTML table format sent using mutt in outlook

Here is my sample html code:
when I send this as an email using mutt to my outlook, the output is as follows:
The command I used is:
mutt -e "my_hdr Content-Type: text/html" -s "Subject: my subject" mymail#outlookmail.com < sampletable.html
In the second table there is some different format. First table is not looking good as well.
If there are more than 2 tables, all the alternate tables are having the same format as second one.
How to make my email look good?
PS: I am generating this sample html table code using awk in a bash script.
Thanks in advance.
replace ending <tr> by closing tr : </tr>.

How to use SQL Server agent to run a Powershell command to generate a CSV file?

I have a PowerShell command like this:
Search-ADAccount -AccountDisabled -UsersOnly | FT Name
> C:\Users\hou\Downloads\DisabledAccount.csv
This command can grab all disabled account names from AD and put it into a .CSV file.
I want to set up a job in SQL Server agent so it will run the command whenever I need it.
But the Agent keep gives me error when I was trying to run the job.
Can anyone let me know the right command for this while running in SQL Server agent?
You might have other issues but the glaring first one you have is you do not have a CSV file. If you opened the file you would see that it is not following any CSV standard but that of a formatted table.
Search-ADAccount -AccountDisabled -UsersOnly |
Export-CSV -notypeinformation C:\Users\hou\Downloads\DisabledAccount.csv
Format-Table is just for showing information on the screen. Not for use of generating output. If you want to make a CSV then that is what Export-CSV is there to do. If you only wanted the name column then you could add a Select-Object in the pipe.
Search-ADAccount -AccountDisabled -UsersOnly |
Select-Object Name |
Export-CSV -notypeinformation C:\Users\hou\Downloads\DisabledAccount.csv

Powershell 4.0 - plink and table-like data

I am running PS 4.0 and the following command in interaction with a Veritas Netbackup master server on a Unix host via plink:
PS C:\batch> $testtest = c:\batch\plink blah#blersniggity -pw "blurble" "/usr/openv/netbackup/bin/admincmd/nbpemreq -due -date 01/17/2014" | Format-Table -property Status
As you can see, I attempted a "Format-Table" call at the end of this.
The resulting value of the variable ($testtest) is a string that is laid out exactly like the table in the Unix console, with Status, Job Code, Servername, Policy... all that listed in order. But, it populates the variable in Powershell as just that: a vanilla string.
I want to use this in conjunction with a stored procedure on a SQL box, which would be TONS easier if I could format it into a table. How do I use Powershell to tabulate it exactly how it is extracted from the Unix prompt via Plink?
You'll need to parse it and create PS Objects to be able to use the format-* cmdlets. I do enough of it that I wrote this to help:
http://gallery.technet.microsoft.com/scriptcenter/New-PSObjectFromMatches-87d8ce87
You'll need to be able to isolate the data and write a regex to capture the bits you want.

Why does this work (or how)?

In my email today I received an email about getting unused drive letters. This was their solution:
Get-ChildItem function:[d-z]: -Name | Where-Object {-not (Test-Path -Path $_)}
PowerShell Magazine BrainTeaser had this for a solution, same thing.
ls function:[d-z]: -n|?{!(test-path $_)}|random
I have no idea how function:[d-z]: works. I know that for each character between 'd' to 'z' is used but I don't know why the syntax works.
Testing Get-ChildItem function:[d-a]: -Name gives you an error saying Get-ChildItem : Cannot retrieve the dynamic parameters for the cmdlet. The specified wildcard pattern is not valid:[d-a]:
So is that a dynamic parameter? How come is does not show up with Get-Help gci -full?
function: is a PSDrive which exposes the set of functions defined in the current session. PowerShell creates a function for each single letter drive, named as the letter followed by a colon.
So, function:[d-z]: lists the functions from "d:" through "z:"
function:[d-a]: doesn't work because , d-a isn't a range of letters.