PowerShell: Text-to-Speech Examples

Posted by Kris Powell

Oct 30, 2014 3:53:03 PM

This is a fun way to utilize Text to Speed (TTS) with PowerShell for Halloween. This is a fun little prank you can use to turn your users kris_resizedcomputers into "haunted" computers as long as they've got their speakers on. 

We use the cmdlet Add-Type to add a .NET framework type to a PowerShell session. We can then instantiate a SpeechSynthesizer object to turn our text into audio output. It’s pretty exciting.

The easiest way to try this is like so:


Add-Type -AssemblyName System.speech
$speak = New-Object System.Speech.Synthesis.SpeechSynthesizer
$speak.Speak('Hello...')

You can even jazz it up a bit by modifying the speed of speech by modifying the rate property of the object.  Here’s a good resource to see the different properties/methods of this object - link (scroll towards the bottom).


Add-Type -AssemblyName System.speech
$speak = New-Object System.Speech.Synthesis.SpeechSynthesizer
$tts.Rate   = -5  # -10 to 10; -10 is slowest, 10 is fastest
$speak.Speak('Hello...')

From there, we can start having some fun. For example, we could place a list of phrases into an array or a separate text file and pull a phrase at random to be synthesized. Be sure to choose which method you’d like to use.

 

Add-Type -AssemblyName System.speech
$tts = New-Object System.Speech.Synthesis.SpeechSynthesizer

# Importing from text file
$PhraseLocation = "C:\SomeFolder\ListOfPhrases.csv"
$Phrase         = (Get-Content $PhraseLocation) | Get-Random

# Using an array
$Phrase2 = @("I'm a robot.", 
    "Help, I'm stuck in the machine!", 
    "What are you doing, $env:USERNAME") | Get-Random

$tts.Rate   = 0  # -10 is slowest, 10 is fastest
$tts.Speak($Phrase)

Hopefully, this gives you some fun ideas for Halloween tomorrow!

Bonus:

Those of you who want to experiment with even more control over TTS can make use of Speech Synthesis Markup Language (SSML).

Here's an example:

Add-Type -AssemblyName System.speech
$tts = New-Object System.Speech.Synthesis.SpeechSynthesizer

$Phrase = '
<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" 
    xml:lang="en-US">
    <voice xml:lang="en-US">
    <prosody rate="1">
        <p>Normal pitch. </p>
        <p><prosody pitch="x-high"> High Pitch. </prosody></p>
    </prosody>
    </voice>
</speak>
'
$tts.SpeakSsml($Phrase)
Read More

Beat the Java Error 1603 When Deploying

Posted by Shane Corellian

Oct 28, 2014 4:32:00 PM

Greetings fellow Sys Admins. If you, like me, are responsible for installing Java on all of your company's Windows computers then you have mostshane_aug_web-1 assuredly seen the dreaded 1603 error code. The video at the bottom of this post shows a Java 1603 error fix. 

What is a Java Error 1603?

This is a Windows Installer (MSI) error that simply means "Fatal error during installation". This error usually means that "something the installer expected wasn't available" or "Something exists that the installer didn't expect". 

There are a number of reasons why 1603 is thrown. Rather than try to go into all the different reasons why this could happen (the number of reasons are too voluminous for a simple blog) I will quickly mention a few and then show you a great way to overcome this problem when it comes to Java. So pour a Guinness and listen (read) up.

Possible Reasons for a Java Error 1603 

  • A required installation file is missing such as the data1.cab file if you are installing using the extracted MSI in Java 7. (Java 8 no longer uses a separate .cab file as all the necessary files are embedded in the actual MSI). 
    • If you are deploying Java then an AV solution may delete the included files thus causing the installer to throw a 1603.

 

  • There are remnants of a previous Java installation.
    • When Java is installed (by default) it attempts to uninstall previous updates in the same family. e.g. Installing Java 7 Update 71 will uninstall Java 7 Update 67 but NOT Java 6 or Java 8.
    • Sometimes previous updates are not completely uninstalled. When this happens a 1603 error can occur when the new version tries to install.
    • Sometimes the only remnant (that can still cause a failure) is a stray registry key! (seriously)

 

  • Java is currently being used when the installation begins. This is fairly common when you attempt to deploy the jre-7uxx-windowsxx.exe and the target computer is running Java in a browser. 

 

  • You are attempting to deploy the online Java exe. If you are deploying the EXE (and not the extracted MSI) then it is imperative that you only install the offline version. A quick way to tell is if your install file contains the letters "iftw" in the name. (e.g. jre-8u11-windows-i586-iftw.exe). Iftw means "Install From The Web". This file is very small (usually < 2 MB). NEVER deploy this file. First of all the online version usually includes the Ask Toolbar which we all know really, really sucks and is actually worse than any 1603 error you'll ever run into. Just grab the offline file from Java, or better yet just use the Java packages from the PDQ Deploy Package Library. This link will take you the latest Java offline downloads for Java 8. This link will take you to the Java 7 downloads. (Once again, choose the Offline versions)

Resolving Java Error Code 1603

OK, those are some common reasons. Now here is the easy way to get around these problems.

Use PDQ Deploy to install Java on your Windows' computers. Here is a screenshot of the latest Java 8 packages in the PDQ Deploy Package Library.

Java8Packages

In most cases you can simply deploy the Java 8 Update 25 package. For computers that have problems installing this then we recommend using the ALTERNATE package. You will need a Pro or Enterprise mode license to access these packages. You can get a trial license of PDQ Deploy Enterprise and import your first three packages free of charge. 

Here is a video showing how Lex and I deploy Java to some machines and then deploy the ALTERNATE package to one failed computer.

 

 

 

Read More

Topics: java

Using the Adobe Customization Tool to Silently Install Reader XI

Posted by Annalisa Williams

Oct 20, 2014 1:10:00 PM

Do you need to customize?

Using the Adobe Customization Tool you can build a simple customized installation for Adobe Reader XI, but do you need a customized version? You can also use a pre-built package from the PDQ Package Library to silently install Adobe Reader XI with many of the customizations users choose anyway, such as removing desktop icons and stopping auto-updates. Still want to customize? Keep reading.

Before you get started with these steps you want to make sure you have the most recent version of Reader downloaded and of course, the Adobe Customization Wizard for your version of Reader. 

Extract the .MSI and Open in the Adobe Customization Tool

After downloading from the above link, open a command window and run the following:

AdbeRdr11000_en_US.exe -nos_o"<path_to_extract_files>" -nos_ne
adobe-customization-wizard-11-03-1

Once you've run the command you should be able to navigate to the AcroRead.msi from the Customization Wizard (File>Open Package).

Customize Your Adobe Reader Installation

For a silent installation of Adobe Reader we recommend you change the following settings:

Personalization Options

  • Check EULA Option "Suppress display of End User License Agreement (EULA)"

Installation Options

  • Under "Run Installation" section, select "Silently (no interface)". 
  • Under "If reboot required at end of installation" section, select "Suppress reboot". 
  • Additionally, under installation options you can have older versions of reader removed or set the default PDQ viewer. 

You may also want to consider making modifications to Online and Adobe online services to disable updates and purchase options. 

adobe-customization-wizard-acrobat-1

Create Transform File and Deploy

Go to Transform> Generate Transform to create your .MST file. In PDQ Deploy (you can use the free download to do this) create a new package (File>New Package) and use an install step. Click the ellipses by the Install File field and navigate to the AcroRead.msi. Select "Include Entire Directory" so that all .MST, .CAB and .INI files are included.

In the parameters field you will reference the .MST by entering: TRANSFORMS="AcroRead.mst." Then, easy enough, save, close and click deploy to select your target machines and deploy. 

Now, yes you can do all of this with Free mode but if you want to add additional steps such as a command to kill Adobe Reader processes prior to installation or schedule this to deploy during off-hours you'll need PDQ Deploy Pro or Enterprise mode (free trial key for that here, just enter the key into your download of PDQ Deploy).

 

 

Read More

Topics: adobe reader

PowerShell: Zip up files using .NET and Add-Type

Posted by Kris Powell

Oct 16, 2014 10:00:00 AM

I recently came across a need to zip up some files prior to copying them over the network. Normally, I’d simply use kris_resizedanother tool such as WinZip or 7zip, but I thought I’d like to see how PowerShell could handle it.

There are many tools out there to help you with this (7zip cli, PowerShell community extensions, etc). They’re not included with Powershell, so I decided to try and make use of the tools we have at hand.

I decided to go with a quick way to zip up files by leveraging .NET and using the cmdlet Add-Type

Zipping files with PowerShell

Note: This requires .NET 4.5 and Powershell 3+

This example script is pretty straightforward and simple.  It makes use of the System.IO.Compression.Zipfile class that was included with .NET 4.5.  We make use of the PowerShell cmdlet Add-Type to add a Microsoft .NET Framework type to the PowerShell session.  This allows to leverage .NET in our PowerShell scripts.

#############################################################################
#
# -SourceFolder    = The folder with the files you intend to zip
# -DestinationFile = The zip file that you intend to create
# -Compression     = The type of compression you'd like to use:
#                         Optimal (default option)
#                         Fastest
#                         NoCompression
# -IncludeParentDir = Setting this option will include the parent directory
#
#############################################################################

$SourceFolder    = "C:\temp\Zip This Folder"
$DestinationFile = "C:\temp\NewZip.zip"
$Compression     = "Optimal"  # Optimal, Fastest, NoCompression

Zip-Directory -DestinationFileName $DestinationFile `
    -SourceDirectory $SourceFolder `
    -CompressionLevel $Compression ` #Optional parameter
    -IncludeParentDir #Optional parameter

function Zip-Directory {
    Param(
      [Parameter(Mandatory=$True)][string]$DestinationFileName,
      [Parameter(Mandatory=$True)][string]$SourceDirectory,
      [Parameter(Mandatory=$False)][string]$CompressionLevel = "Optimal",
      [Parameter(Mandatory=$False)][switch]$IncludeParentDir
    )
    Add-Type -AssemblyName System.IO.Compression.FileSystem
    $CompressionLevel    = [System.IO.Compression.CompressionLevel]::$CompressionLevel  
    [System.IO.Compression.ZipFile]::CreateFromDirectory($SourceDirectory, $DestinationFileName, $CompressionLevel, $IncludeParentDir)
}

#############################################################################
 
Read More

Topics: powershell

Which Java 7 (or 8) Version Should I Deploy?

Posted by Shane Corellian

Oct 15, 2014 4:57:00 PM

Ha! Oracle released three new Java updates on October 14th. The obvious question is: Which Java update should I apply?

Java 7 Update 71

Java 7 Update 72

Java 8 Update 25

The answer, as usual, depends on the needs of your organization. If you have been using Java 7 then it's safe to continue using that Java family for now. I would, however, recommend that you deploy Java 8 to a few "test" computers so that you can prepare for the inevitable move to Java 8. It's important to note that Java 7 reaches its EOL (End of Life) in April, 2015.

If you're sticking with Java 7 then Oracle recommends that you deploy Update 71. From Oracle: "[Update 71] is the intended upgrade for most users." This update contains only security fixes. 

As far as Update 72 Oracle has this to say:"[Update 72] is available for developers and users requiring additional non-security improvements or for testing updated features.  You should use 7u72 if you are facing any of the specific issues as noted in its release notes, and also as part of your quality assurance cycles. These improvements and features are planned to appear as part of the next scheduled CPU in January 2015."

The PDQ Deploy Package Library has added Update 71 for Java 7 and Update 25 for Java 8. If you have Auto Deployments configured for Java then these are the versions that will (by default) be deployed.

blog-javau71-autodeployment

If there is a sufficient demand then we will certainly add Update 72 to the Package Library although it would be a separate package altogether, which means that PDQ Deploy users who have Auto Deployments configured for Java 7 wouldn't have Update 72 applied as a natural upgrade to earlier Java 7 versions.

If you use the Collection Library in PDQ Inventory then you may notice that computers running Update 71 or Update 72 will be placed in the Java 7 (Latest) collections. (See image below.)

blog-java7u71-collections

If you do need to use Java in your organization it is definitely worth the effort to test Java 8. Find out which (if any) of your Java applications or websites don't work with it. It's important to note that Oracle has now made Java 8 the default Java download on their site. If you use Java 8 then it is recommended to deploy Update 25.

Use PDQ Deploy to silently install Java in your environment, it's what we're here for after all!

Read More

Topics: java

PowerShell: Sending Email (with Gmail example)

Posted by Kris Powell

Oct 9, 2014 10:55:44 AM

It’s late on a Friday night. Like most people, you have somewhere else you would rather be. Instead, you are stuck atkris_resized work because you completely forgot about some scheduled maintenance that has to be done that night.

You’re familiar enough with PowerShell to make some scripts to take care of the maintenance, but you’re worried about the off-chance that one of the scripts fails or you’re worried that something could go wrong.

Wouldn’t it be great if you could start your scripts and configure them to email you the results? You could still get out, enjoy your Friday night and rest assured that you’re scripts are doing their job without you losing yours!

(Disclaimer: We do not condone the shirking of any responsibilities that you may have...especially on Friday nights.)

Sending Email with PowerShell

There are a multiple ways to send an email with PowerShell. This is a native cmdlet option that is simple and easy to use. It uses the cmdlet Send-MailMessage.

Send-MailMessage <parameters>

List of available parameters

-Attachments string
    The full path and filenames to be attached to the email.

-Bcc string
    Email addresses that you would like to bcc.

-Body string
   The body of the email message.

-BodyAsHtml
   Indicates that the value of the Body parameter contains HTML.

-Cc string
   Email addresses that you would like to cc.

-Credential PSCredential
   An account that has permission to send the email. The default is the current user.

-DeliveryNotificationOption Option
   Delivery notifications will be sent to the email address specified in the -From parameter.

          None - No notification (default)
          OnSuccess - Notify if the delivery is successful.
          OnFailure - Notify if the delivery is unsuccessful.
          Delay - Notify if the delivery is delayed.
          Never - Never notify.

-Encoding Encoding
   The encoding used for the body and subject. 

-From string
   
The address from which the mail is sent.

-Priority Priority
   
The priority of the email message. Valid values: Low, Normal (default), High

-SmtpServer string
   The name of the SMTP server that sends the email message.

-Subject string
 
  The subject of the email message.

-To string
   
The addresses you wish to send email to. 

-UseSsl
    
Use the Secure Sockets Layer (SSL) protocol to establish a connection to the SMTP server to send email. SSL is not used by default.

Examples of Usage:

Example 1 - Sending a simple email

Send-MailMessage -From “email@yourdomain.com” -To “AnotherEmail@yourdomain.com” -Credentials (Get-Credential) -SmtpServer “smtp.yourdomain.com”

Example 2 - Sending an email from Gmail

Here’s a full example of sending an email via Gmail’s SMTP servers.  It will prompt you for a username and password thanks to (Get-Credential).  The username needs to be <your full gmail address> and password needs to be <your gmail password>, though you could always pipe in a PSCredential and get the same effect.

 

##############################################################################
$From = "YourEmail@gmail.com"
$To = "AnotherEmail@YourDomain.com"
$Cc = "YourBoss@YourDomain.com"
$Attachment = "C:\temp\Some random file.txt"
$Subject = "Email Subject"
$Body = "Insert body text here"
$SMTPServer = "smtp.gmail.com"
$SMTPPort = "587"

Send-MailMessage -From $From -to $To -Cc $Cc -Subject $Subject `
-Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl `
-Credential (Get-Credential) -Attachments $Attachment

##############################################################################

 Best of luck to you in your emailing endeavors!

Read More

Topics: powershell

How to Disable Java Automatic Updates

Posted by Annalisa Williams

Oct 8, 2014 10:36:00 AM

o you're just the kind of control freak that wants control over when and how Java gets updated. It's okay, you're in good company here. We all know who is really in charge of keeping the world (er, the company...we meant company) from falling into shambles (read: sys admins). 

So here's how to disable Java automatic updates.

Finding Where Java Automatic Updates are Enabled

First step is to find the registry key that enables Java's auto updates. Using PDQ Inventory, you can setup a scanner to locate the key. In PDQ Inventory go to File>Preferences>Scan Profiles. Click Add to create a new scan profile, in the pop up click Add>Registry. Here you will specify the path the key resides which will be HKEY_LOCAL_MACHINE hive, with the path SOFTWARE\JavaSoft\Java Update\Policy (the video below provides shows more in depth explanation on finding the path.) 

 

 

You can duplicate that scan that you just created by right clicking and selecting duplicate. Change the path to SOFTWARE\Wow6432Node\JavaSoft\Java Update\Policy to pick up the 32-bit Java installations that are running on 64-bit machines. 

Building a Collection 

Next, you'll want to build a collection of computers you need to make the change from enabled to disabled. 

Go to File>New Dynamic Collection (or Ctrl+N) and build a collection like the following: 

Collection_Java_Auto_Update

 

The below video demonstrates and discusses this dynamic collection and how to also build a report from the data: 

 

 

Silently Changing the Auto Update Policy 

Now that you've targeted which computers have auto updates enabled, it's time to disable all of them. In PDQ Deploy, create a new deployment package (File>New Package). You'll need to create two command steps, one for 32-bit and one for 64-bit machines. (Make sure that you change the architecture respectively under the "Conditions" tab for each step.)

Your command for the 32-bit will be:

%SystemRoot%\System32\Reg.exe DELETE "HKLM\SOFTWARE\JavaSoft\Java Update" /f

Your command for the 64-bit will be:

%SystemRoot%\System32\Reg.exe DELETE "HKLM\SOFTWARE\Wow6432Node\JavaSoft\Java Update" /f

Now you're ready to deploy these commands to the computers you've selected in the collection you've made earlier. Hit Deploy>Deploy Once and under the Choose Targets button select PDQ Inventory. You should see your collection name in the list and can add all or as many of the computers you want to send the deployment out to.

You're all set! The video below shows these steps in detail and how you can verify the key has been removed. 

 

See all the videos in this playlist.

 

 

Read More

Topics: java

Powershell: Get CPU Usage for a Process Using Get-Counter

Posted by Kris Powell

Oct 2, 2014 11:08:00 AM

I was on Stack Overflow not too long ago when I came across a post involving gathering CPU usage bykris_resized percentage that I simply couldn’t pass up. I had to see how PowerShell would handle it.  

I wasn’t disappointed.

After a few revisions, here is a neat way to get the CPU usage of a particular process and have it displayed by CPU percentage.

Be sure to choose between option A or option B. I currently have option B commented out.

#############################################################################
# Option A: This is if you just have the name of the process; partial name OK
$ProcessName = "cpu"

# Option B: This is for if you just have the PID; it will get the name for you
#$ProcessPID = "6860"

#$ProcessName = (Get-Process -Id $ProcessPID).Name
$CpuCores = (Get-WMIObject Win32_ComputerSystem).NumberOfLogicalProcessors
$Samples = (Get-Counter "\Process($Processname*)\% Processor Time").CounterSamples
$Samples | Select `
InstanceName,
@{Name="CPU %";Expression={[Decimal]::Round(($_.CookedValue / $CpuCores), 2)}}
#############################################################################

This makes use of the Get-Counter cmdlet that allows you to get performance counter data for local/remote machines. Let's find out more! The following command will get you a lot of information about all the counter sets that are available to use.

Get-Counter -ListSet *

It's a lot of information. Too much for me, in fact, which is why I usually use the following command. It will get you a list of all the sets of counters that are available to be used:

Get-Counter -ListSet * | Sort-Object CounterSetName | Format-Table CounterSetName

In that list, I see an object called Processor that I'd like to know more information about and which counters are available. I would find out more information like this:

Get-Counter -ListSet Processor

That gets a lot of information. I'd like to see the counters themselves as I would use them with Get-Counter:

(Get-Counter -ListSet Processor).Counter

Now we should have a list that includes "\Processor(*)\% Processor Time" This is what I used to find out the percentage of CPU time for the process. The asterisk (*) in this case is a wildcard grabbing all processes. In the script above, we populate that with the process name that we'd like the know the CPU percentage for.

We also make use of the Get-WMIObject cmdlet to get the total logical processors for the system. This cmdlet is one of the most useful in Powershell and we will likely post many blogs that include Get-WMIObject. Due to how much information can be gleaned from a system by using this cmdlet, we will not go into too much detail at this point in time.

Read More

Topics: powershell

How To Install Firefox Silently

Posted by Annalisa Williams

Oct 1, 2014 12:18:39 PM

There a couple ways to silently install Firefox. First, you'll want to get your free download of PDQ Deploy and do the initial set up. There is a more in-depth explanation on how to build your own deployment packages here. 

To create the package you will go to File>New Package. Name your Firefox package. In the Install step click the ellipsis button in the Install File and navigate to the Firefox Setup xx.exe file. 

At this point you have two options to do a silently install Firefox. In the parameters field you can type

-ms

or use an INI file. Copy and paste the following into a text file and save as a .INI in the same directory as your Firefox setup exe. 

[Install]
InstallDirectoryName=Mozilla Firefox
CloseAppNoPrompt=true
QuickLaunchShortcut=true
DesktopShortcut=true
StartMenuShortcuts=true

Then in the parameters field enter:

/INI=<full path to the INI>\Firefox.ini

In the Additional Files field add the Firefox.ini file.  (You could also just check the Include Entire Directory checkbox but if you do this you want to make sure there aren't unnecessary files in the directory such as earlier Firefox Setup executables)

firefox

Now you're all set to deploy your silent install. Now, the easier way to do this of course is to deploy it from the package in the Package Library that silently installs Mozilla Firefox that is available with either a PDQ Deploy Pro mode or Enterprise mode license. Easier yet, with Enterprise mode you can set up Firefox to automatically deploy whenever a new version is released. 

Note: Do not use /S (a common silent install parameter) because /S for Firefox performs a silent uninstall

Read More

Topics: install silently

Attaching Multiple Packages to an Auto Deployment Schedule

Posted by Annalisa Williams

Sep 29, 2014 12:24:00 PM

One nifty thing about setting up Auto Deployments is you can attach multiple packages from the Package 150pxAutoDLibrary to a single Auto Deployment schedule. The video below is a tutorial on how attaching and detaching packages to a single schedule works. 

While in the Package Library click the checkboxes next to the applications you would like grouped in the same schedule. Once you have those selected you can go ahead and click the "Add Auto Deployment" button in the upper right corner of your screen. This will bring up a window that will allow you to set the frequency at which your schedule runs and what workstations you want to this schedule to deploy to.

Attaching and Detaching Packages

After you have made your schedule you may want to make changes to your Auto Deployment Schedule.

Making changes to an already existing auto deployment schedule is easy, you can easily add or remove packages by opening up the schedule (All Schedules, then double-click the schedule you wish to modify and click the packages tab) from here you have two buttons in the upper right corner, Detach from Selected or Attach to Package. Remove packages by selecting them and clicking Detach from Selected. Add new packages by clicking attach to package. You can come back to this window at anytime and make changes. 

multiple_package_auto_deployment

When attaching new packages, be sure to select the packages from the package library and NOT the packages folder. If you select from the packages folder (imported packages) you will not get the latest versions of applications as the come out, it will only deploy that version of the application.

In an earlier blog we also explained how approval periods work and how to change your approval policy for individual packages as well as your default approval policy for all auto deployment schedules. A video tutorial on that is available in that blog post. Below is a tutorial showing how to attach and detach packages from an auto deployment schedule. 

Read More

Topics: Auto Deployments

Admin Arsenal Blog

Subscribe to Email Updates