Description
Enable or disable Remote Desktop
Data Source
$Terminal = Get-WmiObject Win32_Terminal –Computer "ComputerName"
$Terminal.Enable($True)
Source Code and Samples
Friday, 23 February 2007
Thursday, 15 February 2007
Convert or export word documents to PDF
Description
Convert or export word documents to PDF
Data Source
#You need to install "Microsoft Office 2007 Add-in: Microsoft Save as PDF or XPS"
$word = new-object -ComObject "word.application"
$doc = $word.documents.open("C:\document.doc")
$saveaspath = [ref] "c:\document.pdf"
$formatPDF = [ref] 17
$doc.SaveAs($saveaspath,$formatPDF)
$doc.Close()
Convert or export word documents to PDF
Data Source
#You need to install "Microsoft Office 2007 Add-in: Microsoft Save as PDF or XPS"
$word = new-object -ComObject "word.application"
$doc = $word.documents.open("C:\document.doc")
$saveaspath = [ref] "c:\document.pdf"
$formatPDF = [ref] 17
$doc.SaveAs($saveaspath,$formatPDF)
$doc.Close()
Convert or export word documents to XPS
Description
Convert or export word documents to XPS
Data Source
#You need to install "Microsoft Office 2007 Add-in: Microsoft Save as PDF or XPS"
$word = new-object -ComObject "word.application"
$doc = $word.documents.open("C:\document.doc")
$saveaspath = [ref] "c:\document.xps"
$formatXPS = [ref] 18
$doc.SaveAs($saveaspath,$formatXPS)
$doc.Close()
Convert or export word documents to XPS
Data Source
#You need to install "Microsoft Office 2007 Add-in: Microsoft Save as PDF or XPS"
$word = new-object -ComObject "word.application"
$doc = $word.documents.open("C:\document.doc")
$saveaspath = [ref] "c:\document.xps"
$formatXPS = [ref] 18
$doc.SaveAs($saveaspath,$formatXPS)
$doc.Close()
Send mails from powershell
Description
Send mails from powershell
Source Code
$smtp = New-Object system.net.mail.smtpclient("smtp.server.com")
$smtp.send("fromuser@hotmail.com","touser@hotmail.com", "PowerShell script sample","You can see more powershell scripts in http://powershellscripts.blogspot.com")
Send mails from powershell
Source Code
$smtp = New-Object system.net.mail.smtpclient("smtp.server.com")
$smtp.send("fromuser@hotmail.com","touser@hotmail.com", "PowerShell script sample","You can see more powershell scripts in http://powershellscripts.blogspot.com")
Wednesday, 14 February 2007
Connect to Sql Server and execute SQL statements
Description
Connect to Sql Server and execute SQL statements
Data Source
$Table = new-object System.Data.DataTable
$sqlConn = new-object System.Data.SqlClient.SqlConnection("Data Source=Server\sqlexpress;Initial Catalog=dbProducts;Integrated Security=True")
$adapter = new-object System.Data.SqlClient.SqlDataAdapter("Select * from Products",$sqlConn)
$adapter.Fill($Table)
write-output $table
Connect to Sql Server and execute SQL statements
Data Source
$Table = new-object System.Data.DataTable
$sqlConn = new-object System.Data.SqlClient.SqlConnection("Data Source=Server\sqlexpress;Initial Catalog=dbProducts;Integrated Security=True")
$adapter = new-object System.Data.SqlClient.SqlDataAdapter("Select * from Products",$sqlConn)
$adapter.Fill($Table)
write-output $table
Search Strings In Word Documents
Description
Search Strings In Word Documents
Data Source
$SearchText = $args[0]
$word = new-object -ComObject "word.application"
$path = pwd
if ($args.length > 1) {
$docs = $args[1]
}
else {
$docs = "*.doc"
}
foreach ($a in $(get-childitem $docs -name)) {
$doc = $word.documents.open("$path\$a")
if ($doc.content.find.execute("$SearchText")) {
write-host $a
}
$doc.close();
}
Search Strings In Word Documents
Data Source
$SearchText = $args[0]
$word = new-object -ComObject "word.application"
$path = pwd
if ($args.length > 1) {
$docs = $args[1]
}
else {
$docs = "*.doc"
}
foreach ($a in $(get-childitem $docs -name)) {
$doc = $word.documents.open("$path\$a")
if ($doc.content.find.execute("$SearchText")) {
write-host $a
}
$doc.close();
}
Archive and pack IIS log files
Description
Archive and pack IIS log files.
Source Code
$WinRar = "C:\Program Files\WinRAR\rar"
$TodaysLogFile = get-date -Uformat %y%m%d
$TodaysLogFile = "ex$TodaysLogFile.log"
$LogFiles = ls *.log
if ($LogFiles) {
foreach ($File in $LogFiles) {
$FileName = $File.Name
if ($FileName -ne $TodaysLogFile) {
echo "Compressing $FileName"
&$WinRar m "$FileName.rar" $FileName
}
}
}
Archive and pack IIS log files.
Source Code
$WinRar = "C:\Program Files\WinRAR\rar"
$TodaysLogFile = get-date -Uformat %y%m%d
$TodaysLogFile = "ex$TodaysLogFile.log"
$LogFiles = ls *.log
if ($LogFiles) {
foreach ($File in $LogFiles) {
$FileName = $File.Name
if ($FileName -ne $TodaysLogFile) {
echo "Compressing $FileName"
&$WinRar m "$FileName.rar" $FileName
}
}
}
Subscribe to:
Posts (Atom)