This Command “gem install contint.gem” Hangs Forever

Problem scenario:  You are running gem install *.gem and it hangs.  This stalling appears to be a freeze.  You wait several minutes and nothing happens.  You are waiting for a message or a new prompt.

Solution:  Control-C to get out of it.  Try it again with the "-V" flag like this:

gem install contInt.gem -V

# This time be patient.  Sometimes these commands can take more than 10 minutes to return a message.  The -V flag will provide messages (or more detailed messages) as to the problem you are experiencing.  The -V flag and be placed immediately after the "gem install " or at the very end.  The -V flag is interchangeable with the "--verbose" flag.

Unexpected PowerShell Closures and Controlling the Flow of PowerShell Scripts

Problem scenario:  You PowerShell or PowerCLI window keeps exiting automatically when you run a script.  You find that RAM and CPU are not constrained.  
Root cause: Human error.
Solution:  Look for the "exit" or the "Exit-Pssession" commands.  These can close PowerShell's ISE or PowerCLI.  You may need to eliminate these commands or use a different keyword.

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Problem scenario:  You want to use a for-each loop in PowerShell, you do not want the script to cause the interactive PowerShell window to close, and you want the action portion (in braces {}) to run only once.  What do you do if you do not want to re-write the function to use an "if" or a "while" loop?

Solution:  Use the "break" or "return" key word as the last line in the action clause.

foreach ($cont in $integration) {
   write-host $cont
   return  # or break
}

Return will return the control of the PowerShell interpreter to the previous location before entering the foreach loop.  This is particularly significant when you have functions.  Break can be called with an accompanying label.  For example,
this code would not just interrupt the foreach clause but the PowerShell interpreter would start parsing the ":contInt" section of code:

:contInt if ($foo -eq 289) {
     while ($foo < 505) {
        foreach ($cont in $integration) {
           write-host $cont
           Break :contInt    
         }
      }
}

In the future we want to re-write these directions to use write-verbose instead of write-host. We want to warn people that write-verbose is recommended instead of write-host (according to this posting).

How do you install Jenkins on a RedHat Linux server without an Internet connection?

Problem Scenario 
(If you have an internet connection, see this posting.)  In trying to install the different .rpms (e.g., on CentOS/RHEL/Fedora) for Jenkins you get errors.

For example, here is one command you might try:
yum localinstall springframework-aop-3.2.15-3.fc24.noarch.rpm

This above command may result in an error like this:
"Requires: mvn(org.springframework:spring-beans) = 3.2.15.RELEASE ... Requires: mvn(org.springframework:spring-core) = 3.2.15.RELEASE"

Here is another command you might try: 
yum localinstall jenkins-instance-identity-1.4-5.fc24.noarch
You might see an error like this:
"Requires: mvn(org.bouncycastle:bcpkix-jdk15on)"

To summarize the problem there are numerous dependencies. Installing Jenkins piece-by-piece is tedious.  How do you install Jenkins without internet access?

Solution
Get an .rpm file from this link: http://pkg.jenkins-ci.org/redhat-stable/ 
One of the files will allow for offline (or standalone) installations.

If you need assistance installing plugins without internet access, see this posting.

How Do You Install Pywinrm Without Pip and Without a Yum Repo?

Problem Scenario:  You have CentOS (or a RedHat derivative) and Python is installed.  You want to install pywinrm.  When using Python and Python packages you get this error "gaierror ... 'Temporary failure in name resolution'))."  How do you install pywinrm without pip and without a relevant yum repo?

Root cause:  It can be caused by excessive open connections.  A reboot could fix the problem.  

Solution:  Get the RPM file for pywinrm and its two dependencies.  To do this run these four commands if you have internet access on the Linux machine:

wget ftp://ftp.icm.edu.pl/vol/rzm5/linux-opensuse/repositories/devel:/languages:/python/openSUSE_13.2/noarch/python-pywinrm-0.0.1.99-1.1.noarch.rpm

wget ftp://mirror.switch.ch/pool/4/mirror/fedora/linux/updates/23/armhfp/p/python-isodate-0.5.4-1.fc23.noarch.rpm

wget ftp://ftp.icm.edu.pl/vol/rzm5/linux-fedora-secondary/releases/23/Everything/ppc64/os/Packages/p/python-xmltodict-0.9.0-2.fc23.noarch.rpm

# If the links don't work, find other hosting providers at http://rpm.pbone.net.  If you do not have internet access, download the files to a workstation. Then transfer them to the Linux machine.

yum localinstall python*rpm

# If you prefer, use "rpm -ivh python*rpm"

If you do not have pip installed, have no direct connection to the Internet and no yum repo configured, this solution will still work.

Perl Script Debugging

Problem scenario:  You are running a Perl program and getting an error "syntax error at cool.pl line x, near ...
Global symbol "$foo" requires explicit package name at cool.pl line x..."

Solution:  Find line x - 1, that is, the line before x.  This line may not have a semicolon.  Semicolons are not needed if the Perl script is one line.  Semicolons are not needed for "sub main" declaration lines with a line with just a brace (either "{" or "}").  Perl debugging may not come as easily as Python or Ruby.  But Perl has numerous features.  

By itself the error 'Global symbol "$foo" requires explicit package name at cool.pl line x...' could be the result of trying to use a variable name that has not been declared.  Make sure you have not made a typo in referring to a declared variable.

Here is a sample Perl script that reads in user input and assigns it to a variable named "$foo":

use strict;
use warnings;

sub main
{
    print "Please enter a string and press enter: ";

    my $foo = <STDIN>;

    print "You entered: $contin";
}

main();

How to Create .EXE Files With PowerShell

Problem Scenario 
You want to package a standalone .ps1 script as an .exe file.  How do you create an executable file that does what a PowerShell script does?


Solution 
Install PowerShell Community Extensions.  Then download this .ps1 file and use it according to the conventions in the comments, near the top, of the script itself,

The usage instructions are in the code.  We found that the -NET40 flag was needed.  Here is an example that assumes four things: 1) you saved the file as "Make-PS1ExeWrapper.ps1" (but this is optional and just an example) 2) the script you want to convert is named "good.ps1" 3) the directory the PowerShell prompt is in is the directory with the two files just mentioned 4) you want the new .exe file to be called good.exe.

>  .\Make-PS1ExeWrapper.ps1 .\good.ps1 .\good.exe -NET40

The actions of good.ps1 will run whenever you double click the good.exe file.  You may transfer good.exe to any Windows machine and run it.

How To Install PowerShell Community Extensions

Problem Scenario:  You want the rich features provided by PowerShell Community Extensions (also known as PSCX).

Solution:
1.  Download the .msi from this link
2,  Double click it. 
3.  Install it by accepting the License Agreement and the defaults. 
4.  Open PowerShell as Administrator. 
5. In PowerShell, Change directories to where it was installed (e.g., C:\Program Files (x86)\PowerShell Community Extensions\Pscx3\Pscx). 
6.  Run this command:  import-module .\Pscx.Core.dll

How To Integrate Perl, Ruby, and Python Programs

Problem scenario
You want a Perl program to call a Python program to call a Ruby program to call another Python program.  You are using Linux as the OS.

Solution
Here is a one-line Perl program (course.pl) that calls a Python program:

system( "python /home/ec2-user/cont.py");

Here is a two-line Python program named cont.py.  It invokes a Ruby program.

import subprocess
subprocess.call(['ruby /home/ec2-user/integration.rb'], shell=True)

Here is a one-line Ruby script file named integration.rb (that calls a Python script). 

exec( "python /home/ec2-user/new.py" )

Here is a one-line Python program that prints a basic message, name it "new.py":

print "This final Python script worked!!!"

If each of the above four programs (course.pl, cont.py, integration.rb, new.py) are all in the /home/ec2-user/ directory, just run the Python program like this:  perl course.pl

It will print "This final Python script worked!!!"  This demonstrates integration of three languages with four files and five lines of code. 

Windows Server 2012 Scheduled Tasks Are Not Launching PowerShell Scripts Properly

Problem scenario:  For no apparent reason, Scheduled Tasks are not kicking off PowerShell scripts.  You have configured Scheduled Tasks to launch .ps1 files.The task calls "%windir%\system32\WindowsPowerShell\v1.0\PowerShell_ISE.exe" (in the Action tab's "Program/Script" field) with an argument like this "C:\Program Files\good script.ps"

You manually run the scheduled task (by right clicking its name and choosing Run) and the Scheduled Task will seem to run.  In reality, the .ps1 file will not execute (despite having the correct Execution Policy).  You allow the time to pass when it is scheduled to run.  Still there is no evidence that the job runs.  When you look at the Scheduled Tasks you see a column for "Last Scan Result."  Underneath it you see things like this for the Scheduled Task that never really runs:  "The operation completed successfully" or "0x1".  There are no other hints in the history of whether or not previous runs were successful or not.

Root Cause:  The argument has spaces in it.  There is a space between "Program" and "Files".  There is a space between "good" and "script".

Solution:  Change the location of the .ps1 file to not be in a "Program Files" subdirectory.  The path must have no spaces in it.  Change the name of the .ps1 file to eliminate the space.  Reconfigure the Scheduled Task to have the Action tab's argument field point to the new name and location of the .ps1 file.

Miscellaneous:  Microsoft should have a special parsing feature in PowerShell when this command and flag are ran "schtasks /tr".  In the GUI for Task Scheduler, the argument field should detect spaces and not allow the administrator to leave a space in there.  Spaces can exist in the "Program/Script" field of the action of the Scheduled Task.  But the argument cannot have spaces.  If the argument is encapsulated in single quotes and there is a space in the file name, the "Last Scan Result" can speciously say "The operation completed successfully."  If the argument has double quotes or not quotes with a space in its name, the "Last Scan Result" will show "0x1" while the history will not clearly explain what is wrong.

PowerShell Can Throw a SetInfo With 0 Argument(s) Error When Creating a User

Problem scenario
You run a PowerShell script that has a command setinfo.  For example, the script is like this:

        #...
        $userName = 'jdoe'
        $compName = $env:COMPUTERNAME
        $cona = [ADSI]"WinNT://$compName"
        $user = $cona.Create('User',$userName)
        $user.SetInfo()

You get "Exception calling "SetInfo" with "0" argument(s): "The password does not meet the password policy requirements. Check the minimum password length, password complexity and password history requirements."

You may go to Administrative Tools -> Local System Security and find the Account password requirements are met.  How do you get around this problem?

Solution
Instead of using $user.SetInfo, try this set of commands:

$userName = 'jdoe'
$secretp = 'sp3shulP@ssw0rd'
net user $userName /add $secretp