Create report via email powershell - actionscript-3

function Get-MyLoggedOnUsers
{
param([string]$Computer)
Get-WmiObject Win32_LoggedOnUser -ComputerName $Computer | Select Antecedent -Unique | %{“{0}{1}” -f $_.Antecedent.ToString().Split(‘”‘)[1], $_.Antecedent.ToString().Split(‘”‘)[3]}
}
is there a way I get email alerts for this and add more queries like client name client ip, date and time etc.

Your function needs to be compiled into memory, so when you run this as a script, you need to have the Function declaration (the whole Function Get-My {, then all the way to the final } ) up top, then later on in your code you can run Get-MyLoggedOnUsers and see a list like this one, of your unique users.
Antecedent
----------
\\.\root\cimv2:Win32_Account.Domain="BEHEMOTH",Name="FoxDeploy"
With PowerShell, we can store the output of anything to screen in a variable, and use that instead. So in my code, I'm running your function, capturing it in a variable, and then using that as the body of an e-mail message. I hope the added detail helps.
PowerShell has a built-in cmdlet, Send-MailMessage which you can use if you have an open SMTP forwarder/e-mail server in your environment, like Exchange or something else. You can also use it to send GMail messages.
People have built PowerShell modules for practically every e-mail provider too, so you could use the PSGmail module to just pipe your cmdlet. If you want to use the built-in cmdlet of Send-MailMessage, you'd run the following.
$MailMessage= Get-MyLoggedOnUsers
Send-MailMessage -body $MailMessage -Port 465 -SmtpServer smtp.gmail.com `
-Credential (get-credential) -to Whoever#gmail.com -From Yourname#gmail.com
This will prompt you for your Gmail credentials, and should send the message out. Make sure to type in the right e-mail address for the -To and -From parameters.
As an example of using the built in tool.

Related

How to automaticaly upload .json on daily basis to Firebase

Our company generates a .json on daily basis containing the data for our mobile app which has the database on Firebase. We upload the data to it manualy, but we've been doing it for couple of months now and it is pain in the butt.
Our suplier tried to create a uploader which works with this cmdlet gcsupload-windows.exe /key:"C:\Data\myapp-test-sdk.json" /bucket:"myapp-test.appspot.com" /dst:"Import" "C:\Data\json\*.json" and they created it based on https://github.com/googleapis/google-cloud-go/tree/master/storage, but this is not my expertiese, so I can only tell you what it does.
DevOps created a Win Core server for me, they said it is enough, so I am reliant only to CMD...
Once I go to CMD and type the command outside of the domain it does upload the .json to the server so I am sure that the Uploader and the Command are correct and working properly, BUT when I am in the domain it goes haywire and the cmd replies Failed to get bucket metadata and so on..
CMD Input: PS: D:\Uploader> .\gcsupload-windows.exe /key:"D:\Firebase_Key\myapp-test.json" /bucket:"myapp-test.appspot.com" /dst:"Import-Test" /src:"D:\myapp_json"
CMD Output: Failed to get bucket metadata: Get "https://storage.googleapis.com/storage/v1/b/myapp-test.appspot.com?alt=json&prettyPrint=false&projection=full" oauth2: cannot fetch token: Post "https://oautha.googleapis.com/token" dial tcp 216.58.201.74:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
Proxy is set correctly on my machine and the trafic is all accepted on proxy server.
The suplier said that it might be something with gRPC, but again, this is not my expertiese, so please, wise stackoverflowers ask me, shoot me, just please help me with this. Thank you
For anyone still interested in this...
We stumbled across the solution (more like a workaround) by accident. I tried everything I could find on the internet, I had to add this
$proxyString = "http://proxy:8080" $proxyUri = new-object System.Uri($proxyString) [System.Net.WebRequest]::DefaultWebProxy = new-object System.Net.WebProxy ($proxyUri, $true) [System.Net.WebRequest]::DefaultWebProxy.Credentials=[System.Net.CredentialCache]::DefaultCredentials
just to pick up IE settings, which kind of helped, but it was not enough. Some said to modify the Uploader and give it credentials with which I should authenticate against proxy, but this looked unsafe.
I was helpless, tried invoke-webrequest http://google.com just to be sure if I am connecting to the proxy, tried the command for the uploader again, and voila - it worked!
It looks like invoke-webrequest is doing something like telling everything behind it to work with the proxy, anyway it works. So my whole script is looking like this:
$proxyString = "http://proxy:8080"
$proxyUri = new-object System.Uri($proxyString)
[System.Net.WebRequest]::DefaultWebProxy = new-object System.Net.WebProxy ($proxyUri, $true)
[System.Net.WebRequest]::DefaultWebProxy.Credentials=[System.Net.CredentialCache]::DefaultCredentials
invoke-webrequest http://google.com
$Env:HTTP_PROXY = "http://proxy:8080"
D:\Uploader\gcsuploader.exe /key:"D:\Firebase_key\myapp-prod-firebase-adminsdk.json" /bucket:"myapp-prod.appspot.com" /dst:"Import" "D:\Myapp_json\*.json" >> "c:\Uploader_logs\uploader $(get-date -f yyyy-MM-dd).log" 2>&1

How to ping from Zabbix agent?

Is it possible to ping from Zabbix agent and pass that data into Zabbix server? I would like to be able to get response time from the agent.
I read that it is possible by using fping, would be great if someone could guide me to the correct path.
Thank you,
Rijath Mohammed
While that is not currently available out of the box, you can implement such a functionality using a feature called "user parameters". This forum thread has a simple example:
UserParameter=myping[*],/etc/zabbix/fping -q $1;echo $?
Although for you the path to fping is likely to be /usr/sbin/fping or /usr/bin/fping.
You can read more about user parameters in the official manual: https://www.zabbix.com/documentation/3.0/manual/config/items/userparameters .
While I haven't ever configured that, it would be similar on Windows - see this forum thread for some inspiration.
And if you would like to see this feature implemented out of the box, make sure to vote on this feature request.
Got it working using the below powershell script, :)
$Test = test-connection google.com -count 1
$Test.responsetime
This will just return the response time for Google.com and that value is passed to Zabbix using the below user parameter:
UnsafeUserParameters=1
UserParameter=ping.google,C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe C:\zabbix\pinggoogle.ps1
I am calling this parameter from Zabbix using the key "ping.google"

Adding a hyperlink to an email generated through PowerShell

I have a script that currently does several things. It creates a user account in Active Directory, writes data to a SQL table and sends an email to the account requestor with the account's user name and password.
We'd love to add a hyperlink to that email so that the requestor can click to view their original request form, but I can't quite seem to get the syntax right.
Because double quotes are used in the PowerShell syntax as well as the HTML link, I defined the link as a variable and inserted that variable into the -body section of the email to eliminate double quote confusion, though this may not be necessary.
Can anyone help me insert a link in this email?
Many thanks!
CURRENT COPY:
"The user account you requested (request #$ReqID) has been created."
We'd like $ReqID to hyperlink to the Web form.
THE VARIABLE I'VE DEFINED:
$link = '$ReqID'
But it displays in the email body like this:
The user account you requested (request #$ReqID) has been created.
Help?
Swap your quotes around, i.e.:
$link = "<a href='http://tsturl/detail.aspx?reqID=$reqID'>$ReqID</a>"
Or do:
$link = '$ReqID'
$link = $ExecutionContext.InvokeCommand.ExpandString($link)
Further to your comment, if you want the mail body to render as HTML, an thus display a link, then you'll need to tell your mail client that the body is HTML. $link is just a plain old string and doesn't know that it's HTML.
From your previous question, I'm guessing you're using the Send-MailMessage cmdlet. If so then you need to specify the -BodyAsHtml switch.

Google Maps Geocoding XML service returns error via Curl when city name with more than 1 word is used

I am using the following Google Maps Geocoding service via a php script
http://maps.googleapis.com/maps/api/geocode/xml?address=
I have already tried curl and file_get_contents but none of them worked. The problem is when I use city name with one word it works but when I use city name with two words then I do not get anything back from the service but the following error
That’s an error.
Your client has issued a malformed or illegal request. That’s all we know.
Below is some code snippet from the script
$city = $_GET["c"];
$url="http://maps.googleapis.com/maps/api/geocode/xml?address=$city&sensor=false";
$data = curl_download($url);
//$data = file_get_contents($url);
echo $data;
I have also uploaded the script to the location below
01)http://www.javeria.com/sites/travel/map/googlemap.php?c=Houston (works)
02)http://www.javeria.com/sites/travel/map/googlemap.php?c=New+York (does not work)
When invoked with 02) it won't display the map instead I am masking the error to display a user friendly message.
I would appreciate any help into this matter.
Try using + between the words. I am doing essentially the same thing - and that change makes it work for me.

Reporting services 2008 R2 web services api - how do I manage security permissions?

I'm writing a powershell script to deploy a number of reports to SQL Server Reporting Services 2008 R2 using the SSRS web services. I'm pretty happy with the approach, it was easy to create a new deployment folder and upload the reports. Following is a snippet of code showing creation of a folder :
$reportServerUri = "http://{0}/ReportServer/ReportService2005.asmx" -f $reportServerName
$proxy = New-WebServiceProxy -Uri $reportServerUri -Namespace SSRS.ReportingService2005 -Credential $credential
#Dont currently set any properties so set empty array of properties
$propertyArray = #()
$warnings = $proxy.CreateFolder($folderName, $folderParent, $propertyArray)
However I'd also like to be able to set permissions on the folder and this is where I am a bit stuck. What I want to replicate is where, from the web UI, I would select the security option of the folder and add a user\group against a role.
I thought this might be done through the propertyArray on the createFolder call but I haven't been able to find any information in the docs yet (probed existing properties and can't see anything relevant), I've been looking at http://msdn.microsoft.com/en-us/library/cc282788.aspx for guidance. So reached a dead end there. I thought there might be a specific method to manage permissions at this level but have not been able to identify one.
I am using the ReportingService2005 web services, I know there are also 2010 web services but I havent been able to find what I'm looking for there either.
Does anyone know how I add permissions to folders using the web services api (and presumably a consistent method for other objects like reports and shared data sources)? I assume it must be possible as the web UI allows you to do it. This is not a powershell question but instead about the api's to use to manage permissions.
Update - Below is the snippet of code that seems to do the job. I need to refine this a bit as it looks like the update to policies must include the original list so I need to get the current policies, add my new policy to this and update with the full list. But I'll fix that later!
$Policies = $global:ssrsproxy.GetPolicies($ItemPath, [ref] $InheritsFromParent)
$PolicyAlreadyExists = $false
$Policies | Foreach-Object{ if ($_.GroupUserName -eq $GroupUserName)
{$PolicyAlreadyExists = $true} }
$Policies | Foreach-Object{ $_ | get-member }
if ($PolicyAlreadyExists){
"Policy already applied."
} else {
$Policy = New-Object SSRS.ReportingService2005.Policy
$Policy.GroupUserName = $GroupUserName
$Roles = #()
$Role = New-Object SSRS.ReportingService2005.Role
$Role.Name = $RoleName
$Roles += $Role
$Policy.Roles = $Roles
$global:ssrsproxy.SetPolicies($ItemPath, $Policy)
"Policy applied."
}
Use the SetPolicies method. First define an array of Policy(s) containing group/user and required roles, then pass this array to SetPolicies along with the item.