Test Path
Posted by admin in Powershell on September 24, 2009
Test-Path is used to determine if a file/folder/registry key etc… exists and returns a value of True or False
PS C:\>test-path hklm:\software\microsoft\windows\currentversion\run
True
PS C:\> test-path c:\windows\
True
PS C:\> test-path c:\windows\system31
False
PS C:\> test-path c:\autoexec.bat
True
1 2 3 4 5 6 7 | if (Test-Path c:\temp){
write-host "folder exists"
}
else {
mkdir c:\temp
write-host "folder created"
} |
Get Logged On User
Posted by admin in Powershell on September 21, 2009
A couple of different ways to get the currently logged on user using powershell
(gwmi -class win32_computersystem).username
gwmi -class win32_computersystem | select-object username
To query on a specific computer:
(gwmi -class win32_computersystem -computer ".").username
gwmi -class win32_computersystem -computer "." | select-object username
sending email in powershell
Posted by admin in Powershell on September 21, 2009
Version 1:
$emailFrom = “user@domain.com”
$emailTo = “user@domain.com”
$subject = “subject”
$body = “body”
$smtpServer = “smtp server”
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $body)
Version 2:
PS C:\Windows\system32> get-help send-mailmessage
NAME
Send-MailMessage
SYNOPSIS
Sends an e-mail message.
SYNTAX
Send-MailMessage [-To] <string[]> [-Subject] <string> -From <string> [[-Body] <string>] [[-SmtpServer] <string>] [-Attachments <string[]>] [-Bcc <string[]>] [-BodyAsHtml] [-Cc <string[]>] [-Credential <PSCredential>] [-DeliveryNotificationOption {None | OnSuccess | OnFailure | Delay | Never}] [-Encoding <Encoding>] [-Priority {Normal | Low | High}] [-UseSsl] [<CommonParameters>]
DESCRIPTION
The Send-MailMessage cmdlet sends an e-mail message from within Windows PowerShell.
RELATED LINKS
Online version: http://go.microsoft.com/fwlink/?LinkID=135256
REMARKS
To see the examples, type: “get-help Send-MailMessage -examples”.
For more information, type: “get-help Send-MailMessage -detailed”.
For technical information, type: “get-help Send-MailMessage -full”.
Powershell V2
Posted by admin in Powershell on September 19, 2009
get-hotfix returns the installed hotfixes on local or remote computers
PS C:\Windows\system32> get-help get-hotfix
NAME
Get-HotFix
SYNOPSIS
Gets the hotfixes that have been applied to the local and remote computers.
SYNTAX
Get-HotFix [[-Id] ] [-ComputerName ] [-Credential ] []
Get-HotFix [-Description ] [-ComputerName ] [-Credential ] []
DESCRIPTION
The Get-Hotfix cmdlet gets the hotfixes that have been applied to the local computer or to remote computers by Component-Based Servicing.
RELATED LINKS
Online version: http://go.microsoft.com/fwlink/?LinkID=135217
Get-ComputerRestorePoint
REMARKS
To see the examples, type: “get-help Get-HotFix -examples”.
For more information, type: “get-help Get-HotFix -detailed”.
For technical information, type: “get-help Get-HotFix -full”.