I have a Powershell script that looks for files created in the past 24 hours in a certain folder and then looks for certain filenames which it then outputs to a folder. I would like to output to a hipchat room instead but I'm having trouble passing the variable. My code is below:
$var1 = Get-ChildItem -Path "W:\Blabla" -Recurse | Where-Object { $_.CreationTime -gt (Get-Date).AddHours(-24) } | Select-Object Fullname,CreationTime
Out-File test-24.txt -InputObject $var1
$var2 = Select-String -Path test-24.txt -Pattern "pass|Angie" | select line
Out-File test-out.txt -InputObject $var2
$params = @{
Uri = "https://hipchat.blabla.com/v2/room/456/notification?auth_token=????"
Method = "POST"
Body = @{
color = 'red'
message = "$var2"
notify = $false
message_format = "text"
} | ConvertTo-Json
ContentType = 'application/json'
}
Invoke-RestMethod @params
I'm trying to pass $var2 into the second array but my messages turn out blank. Thank you.