- <#
- .SYNOPSIS
- This script displays the platform id of the system
- .DESCRIPTION
- This script is a rewrite of an MSDN sample. It
- gets System.Environment.Version's Platform field
- and displays it. The sample is simplified from
- the C# version! Not tested except on Server 2008.
- .NOTES
- File Name : Get-PlatformId.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell V2
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN Sample posted at:
- http://msdn.microsoft.com/en-us/library/3a8hyw88.aspx
- .EXAMPLE
- PSH [C:\foo]: .Get-PlatformID.ps1'
- Platform ID: Win32NT
- #>
- ##
- # Start of Script
- ##
- #Get OS Version from System.Environment
- $OS = [System.Environment]::OSVersion
- # Get and display the PlatformID
- $Platformid = $OS.Platform;
- "Platform ID: {0}" -f $Platformid
- # End of script
This blog contains PowerShell scripts, more PowerShell scripts and still more PowerShell scripts. Occasionally you may see some organisational posts.
Sunday, 20 September 2009
Get-PlatformId.ps1
Saturday, 5 September 2009
Send-EmailMessage.ps1
- <#
- .SYNOPSIS
- This script creates and sends an SMTP email message.
- .DESCRIPTION
- This script first creates a System.Net.Mail.Mailmessage, and populates
- it. Next, it creates an system.Net.Mail.SmtpClient, which then sends
- the message to the SMTP Server, and onwards transmission. This script
- is effectively a re-write of the C# sample above.
- .NOTES
- File Name : Send-EmailMessage.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell V2
- .LINK
- This script posted to:
- http://pshscripts.blogspot.com/2009/09/send-emailmessageps1.html
- MSDN Sample posted at:
- http://msdn.microsoft.com/en-us/library/67w4as51.aspx
- .EXAMPLE
- PSH [C:\foo]: .\Send-EmailMessage.ps1'
- Message sent successfully
- #>
- ##
- # Start of Script
- ##
- # Set contents of the Email message
- $To = "doctordns@gmail.com"
- $From = "jane@cookham.net"
- $Subject = "Using the .NET SMTP client."
- $Body = "Using this .NET feature, you can send an e-mail message from an application very easily."
- # Create meil message
- $Message = New-Object System.Net.Mail.MailMessage $From, $To, $Subject, $Body
- # Create SMTP client
- $Server = "cookham8"
- $Port = 25
- $Client = New-Object System.Net.Mail.SmtpClient $Server, $Port
- # Credentials are necessary if the server requires the client
- # to authenticate before it will send e-mail on the client's behalf.
- $Client.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
- # Try to send the message
- try {
- $Client.Send($Message)
- "Message sent successfully"
- }
- # Catch an error
- catch {
- "Exception caught in Send-Emailmessage.ps1"
- }
- # End of Script
Subscribe to:
Posts (Atom)