How do I get notification to my phone, when my PC starts? - windows

I want to know how can I get notification to my phone when my PC goes online (Turns On).

TeamViewer can help you: https://www.teamviewer.com.
If you install this app on your pc and you sync your user on your iPhone, I guess that whenever your pc starts you will get a notification

If your pc have login in, you can create an powershell script for any time when some one login in your pc you receive an email. Or, this is hard, you can creat an powershell script for when an service start on your pc, send you an email too, you set the service on the start.
$filter="*[System[EventID=7036] and EventData[Data='SIOS DataKeeper']]"
$A = Get-WinEvent -LogName System -MaxEvents 1 -FilterXPath $filter
$Message = $A.Message
$EventID = $A.Id
$MachineName = $A.MachineName
$Source = $A.ProviderName
$EmailFrom = "sios#medfordband.com"
$EmailTo = "sios#medfordband.com"
$Subject ="Alert From $MachineName"
$Body = "EventID: $EventID`nSource: $Source`nMachineName: $MachineName `n$Message"
$SMTPServer = "smtp.gmail.com"
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("sios#medfordband.com", "MySMTPP#55w0rd");
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
Like this, the event is the SIOS DataKeeper, when someone start the service you will receive an email. You can set the service for windows start, when the windows start you will receive an email.

Related

How can I set the "Environment" > "Start the following program at logon" property on a local user using powershell?

Background:
I have a server with Windows 2008 R2 installed running as a terminal server session host. I have a long list of local users set-up and configured as remote desktop users. When the users remotely log on using remote desktop connection, a program automatically starts up. When the user closes that program, the session ends. This all works fine if I set it up manually.
My Question:
I have written a script to add a list of local users automatically and setup and configure the properties. The problem is that nowhere can I find how to set the "Environment" > "Start the following program at logon" properties. (See image for the properties I want to set)
A sample portion of my current script is as follow:
$computer = "localhost"
$userName = "aTestUser"
$objComputer = [ADSI]"WinNT://$computer"
$objUser = $objComputer.Create('user', $userName)
$objUser.SetPassword("Password")
$objUser.PSBase.InvokeSet('Description', "Some description for $userName")
$objUser.PSBase.InvokeSet('userflags', 512)
$objUser.PSBase.InvokeSet('passwordExpired', 1)
$objUser.SetInfo();
I also tried this command which doesn't work:
$objUser.PSBase.InvokeSet("TerminalServicesInitialProgram", "C:\programs\a_test_program.exe")
I have searched on Microsoft's MSDN site and Google and StackOverflow but could not find this specific property.
I found a solution here.
$ou = [adsi]"WinNT://127.0.0.1"
$user = $ou.psbase.get_children().find("test")
$user.PSBase.InvokeSet("TerminalServicesInitialProgram", "C:\logoff.bat")
$user.setinfo()
Okay, so I finally got it working. Seems like you have to first create the user then open it again for editing before the InvokeSet sets the TerminalServicesInitialProgram property.
I am not sure, maybe someone can share some experience or explanation.
Thank you to everyone for your help and assistance.
Working Code:
# Read the CSV file and create the users
# The CSV file structure is:
# UserName,FullName,Description
$Users = Import-Csv -Path "C:\Users.csv"
foreach ($User in $Users)
{
# adds user
$computer = "localhost"
$username = $User.UserName
#$username = "atest001"
$fullname = $User.FullName
#$fullname = "My Name"
$description = $User.Description
#$description = "A new user description"
$password = "MyGreatUnbreakableSecretPassword"
$objComputer = [ADSI]"WinNT://$computer"
$objUser = $objComputer.Create('user', $username)
$objUser.SetPassword($password)
$objUser.PSBase.InvokeSet("Description", $description)
$objUser.PSBase.InvokeSet('userflags', 65536)
$objUser.SetInfo();
# set password not to expire
#wmic USERACCOUNT WHERE "Name = '$username'" SET Passwordexpires=FALSE
# Add to groups
$group = [ADSI]"WinNT://./Power Users,group"
$group.Add("WinNT://$username,user")
$group = [ADSI]"WinNT://./WW_Users,group"
$group.Add("WinNT://$username,user")
$ou = [adsi]"WinNT://127.0.0.1"
$user = $ou.psbase.get_children().find($username)
$user.PSBase.InvokeSet("TerminalServicesInitialProgram", "C:\Program Files (x86)\Wonderware\InTouch\view.exe c:\program files (x86)\archestra\framework\bin\sibanyegold-kdce_app_tse1_test")
$user.PSBase.InvokeSet("MaxConnectionTime", 120)
$user.PSBase.InvokeSet("MaxDisconnectionTime", 1)
$user.PSBase.InvokeSet("MaxIdleTime", 30)
$user.PSBase.InvokeSet("BrokenConnectionAction", 1)
$user.PSBase.InvokeSet("ReconnectionAction", 1)
$user.PSBase.InvokeSet("FullName", $fullname)
$user.setinfo()
}

powershell auto login script not working

This is my url
https://webmail.fasttrackteam.com/Login.aspx
I am able to open this path in IE.
but unable to set loginid & password.
Also dont know how to fire click event.
following is code that I have tried.
$ie = New-Object -com InternetExplorer.Application
$ie.Navigate("https://webmail.fasttrackteam.com/Login.aspx")
$ie.visible = $true
$doc = $ie.document
$user = $doc.getElementById("ctl00_MPH_txtUserName")
$password = $doc.getElementById("ctl00_MPH_txtPassword")
$submit = $doc.getElementById("ctl00_MPH_btnEnterClick")
$user.value = "emailid"
$password.value = "password"
$submit.Click();
$ie.Quit();
$ie.Document.body | Out-File -FilePath C:\Users\amol.kshirsagar\Documents\FastTrack\Work\Extra\AutoLogin\log.txt
EDIT
This is error that I am getting,
You cannot call a method on a null-valued expression.
You call the Quit() method before accessing the Document.body member. As the Quit() call, well, quits the application, don't you think it should be somewhat peculiar to access its data afterwards?
Try accessing the member first, then quitting the browser instance.

Server Management - Need script to monitor free space on server

Need script to monitor free space on server and if the free memory space goes done certain threshold send alert mail.
PS- I think the solution will be Power Shell + Windows Timer Job. I am new to Power Shell though.
You can get free disk space using a command like this:
([wmi]"\\$computer\root\cimv2:Win32_logicalDisk.DeviceID='$drive'").FreeSpace
And you cand send an email using the function below:
function Send-EMail
{
param (
[parameter(Mandatory = $false)][string] $EmailTo = "<Your destination email>",
[parameter(Mandatory = $false)][string] $EmailFrom = "<The sending email address>",
[parameter(Mandatory = $false)][string] $EmailSubject = "Disk space problem",
[parameter(Mandatory = $false)][string] $SMTPServer = "<your smtp server>"
)
$MailMessage = New-Object System.Net.Mail.MailMessage
$MailMessage.From = ($EmailFrom)
$MailMessage.To.Add($EmailTo)
$MailMessage.Subject = $EmailSubject
$MailMessage.Body = $EmailBody
$MailMessage.IsBodyHTML = $true
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 25)
$SMTPClient.Send($MailMessage)
}
Now combine these two functions in a PowerShell script that you can schedule with Windows scheduller.
You need to deal with WMI objects.
http://technet.microsoft.com/en-us/library/dd315295.aspx
Scripting might not be necessary. If you are on Wk3 Server you can enable quota management on volumes. W2k8 has extended quota management to volume folders also.
http://technet.microsoft.com/en-us/library/cc733029.aspx

Exchange 2010 - run command on mail receive

Does anyone know is there a way to make Exchange server 2010 execute some program upon mail receive for some mailbox ?
For example:
I have mails test1#example.com and test2#example.com
I want to execute program1.exe when mail arrives to test1#example.com
and execute program2.exe when mail arrives to test2#example.com
I have looked all options in Exchange management console, and didn't find anything similar.
I made something similar using EWS and powershell. You can download EWS
here
Then you can create an script in powershell that use the Exchange web service
This is the example of my script:
$MailboxName = "mail#domain.com"
$dllpath = "C:\Program Files\Microsoft\Exchange\Web Services\2.0\Microsoft.Exchange.WebServices.dll"
[void][Reflection.Assembly]::LoadFile($dllpath)
$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP1)
$service.TraceEnabled = $false
$service.Credentials = New-Object System.Net.NetworkCredential("name","password", "domain")
$service.Url="https://mail.yourdomain.com.au/ews/exchange.asmx"
try{
$fldArray = new-object Microsoft.Exchange.WebServices.Data.FolderId[] 1
$Inboxid = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$MailboxName)
$fldArray[0] = $Inboxid
$stmsubscription = $service.SubscribeToStreamingNotifications($fldArray, [Microsoft.Exchange.WebServices.Data.EventType]::NewMail)
$stmConnection = new-object Microsoft.Exchange.WebServices.Data.StreamingSubscriptionConnection($service, 30);
$stmConnection.AddSubscription($stmsubscription)
Register-ObjectEvent -inputObject $stmConnection -eventName "OnNotificationEvent" -Action {
foreach($notEvent in $event.SourceEventArgs.Events){
[String]$itmId = $notEvent.ItemId.UniqueId.ToString()
$message = [Microsoft.Exchange.WebServices.Data.EmailMessage]::Bind($event.MessageData,$itmId)
IF ($message.Subject -eq "execprocess"){
Start-Process "mybat.bat"
}
}
} -MessageData $service
}catch [Exception] {
Get-Date | Out-File C:\logs\logError.txt -Append
"Error : "+ $_.Exception.Message
}
Register-ObjectEvent -inputObject $stmConnection -eventName "OnDisconnect" -Action {$event.MessageData.Open()} -MessageData $stmConnection
$stmConnection.Open()
Then, run the 2 scripts one for every account you need to monitoring.
See the original example here--> Source
Exchange has no out-of-box way to do this. You might want to look at using Exchange Web Services (EWS) subscriptions in an external service to do this.
One way I accomplished this is by writing a powershell script using outlook com objects to scan the inbox for certain criteria and execute a process based on what it finds.

How can I monitor the Exchange 2003 Event Service from my application?

We had our server guys set up something on Exchange so that for a particular email address, any attachments sent to it will be dumped to a location on the file server.
The Exchange Event Service controls this behaviour, but it seems that this particular service fails fairly often. I dont know why - I dont have access to the Exchange server and it is run by a team in a different country.
Is it possible to monitor this exchange service programatically so I can warn the users if it goes down? I know that the 'right' solution is to have this handled by the Exchange team, but because of the timezone differences (and their massive workload) I really need to handle it from my end.
Could you do something like this with WebDav?
You could use the following powerShell script:
# Getting status of Exchange Services and look for anything that's "stopped"
$ServiceStatus = get-service MSExch* | where-object {$_.Status -eq "stopped"}
# Convert Result to String
$ServiceStatusText = $ServiceStatus | fl | Out-String
# If $ServiceStatus <> $null then send notification
If ($ServiceStatus -ne $null)
{
###Exchange Server Values
$FromAddress = "Exchange-Alert#YOUR_DOMAIN.local"
$ToAddress = "your_address#YOUR_DOMAIN.com"
$MessageSubject = "CRITICAL: An exchange service is has stopped"
$MessageBody = "One or more Exchange services has stopped running or crashed. Please check the server ASAP for possible issues`n"
$MessageBody = $MessageBody + $ServiceStatusText
$SendingServer = "msexch02.pnlab.local"
###Create the mail message and add the statistics text file as an attachment
$SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress, $ToAddress, $MessageSubject, $MessageBody
###Send the message
$SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer
$SMTPClient.Send($SMTPMessage)
}
# Else don't do anything and exit
Else
{
$null
}

Resources