How To Install Pip On Red Hat version 6 with Python 2.7.x Installed

Goal:  You want to install pip on RedHat 6 with Python version 2.7.x installed.
Problem scenario:  
You try "yum install python-pipbut get an error about python(abi) = 2.6 being an unmet dependency.  Trying to install an older version may require you to downgrade other components.  The latest version of Python packages is often safer and recommended. 
Solution:  Obtain a copy of python-pip-7.1.0-1.el7.noarch.rpm.  Install it with yum.  This way you do not have to downgrade various components of Python.

Using Python and Ruby To Read Files

Problem:  You have a Python program that reads in a file named coolFile (in /tmp), and outputs the content to the screen.  The program prints an extra blank line after each line of content of the file named coolFile.  You want the output to not have an extra blank line.  Here is the code:

#/usr/bin/python

x = open("/tmp/coolFile", "r")
for line in x:
        print (line)

How do you have the output now print an extra blank line after each line?

Solution:  Insert a comma after the print (line) stanza.  Here is an example of source code that works:

#/usr/bin/python

x = open("/tmp/coolFile", "r")
for line in x:
        print (line),

Equivalent program in Ruby:  Here is the equivalent method in Ruby (a program that reads in a file, /tmp/coolFile, and prints each line out with no extra line):

#/usr/bin/ruby

File.readlines('/tmp/coolFile').each do |line|
    puts line
end

In PowerShell Diskpart Script Does Not Work (Despite No Error) Via “diskpart /s nameofscript.txt”

Goal:  To use a diskpart.exe script (a file of commands that could be ran interactively in sequence).
Problem:  When you run this command via PowerShell it does not work:  diskpart /s C:\Full\Path\script.txt
The result says something like "Microsoft DiskPart ..." and there is a list of alphabetic diskpart subcommands (ACTIVE to RECOVER).  There is no explicit error.  The diskpart command and script does no work.
Background:  When a PowerShell redirect (>) command is used to save a file, the default encoding is usually Unicode.  This encoding will not work for a diskpart script file (e.g., a .txt file of commands that could run interactively in sequence once diskpart is entered). 
Solution:  To resolve this, open the script, go to Save As, change the "Encoding" from "Unicode" to "ANSI."  Alternatively, if the diskpart script you are using is generated via PowerShell on an ongoing basis, use the Out-File and Encoding flags to designate the file to be ASCII.

How To Solve the PowerShell Error “The term ‘script’ is not recognized…”

Goal:  You want to run a .ps1 file.
Problem:  You get the error "Powershell : script : The term 'script' is not recognized as the name of a cmdlet, At line:1 char:1 + ..."
Solution:  Use the "script" resource section inside of a DSC configuration exclusively.  It will not work or run as a standalone PowerShell script.  Scripts with GetScript, SetScript, and TestScript must be run as part of a DSC configuration.  Also, DSC must be installed for configurations to work.  The "script" block should appear under the "configuration nameOfConfiguration" {} section of the .ps1 file.

One Way To Get Around The Error “Get-targetresource PS module does not implement the key property solution” in DSC

Goal:  Apply DSC configuration
Problem/scenario:   When you run the "start-dscconfiguration NameOfConfig -wait -verbose" (where NameOfConfig is the name of the configuration) from the folder that houses the subfolder with NameOfConfig, you get an error like this:  "Get-targetresource PS module does not implement the key property solution"
Solution:  Stop a specific process by running this command.
gps wmi* |? {$_.Modules.ModuleName -like '*DSC*'} | Stop-Process -Force
Re-run the "start-dscconfiguration NameOfConfig -wait -verbose" command.

Problem and Solution: “New Simple Volume” is Greyed Out After Disk Was Added To Windows Server

Goal:  You want to create a new Disk Partition on Windows Server.
Problem:  You go to Server Manager -> Computer Management -> Storage -> Disk Management.  You right click a newly-added partition (in the graphical bar section that says "Unallocated").  "New Simple Volume," "New Spanned Volume," and "New Striped Volume" are all grayed out.  
Solution:  Right click the "Disk X" (where X is the integer associated with the newly-added disk).  Choose "Online."  Right click the "Disk X" again.  Choose "Initialize Disk."  Now "New Simple Volume" should not be grayed out.

DSC Problem and Solution: One Way To Possibly Solve a “Cannot invoke the SendConfigurationApply” Problem

Goal:  You want to use DSC to apply a configuration.
Problem scenario:  When you run the "start-dscconfiguration NameOfConfig -wait -verbose" (where NameOfConfig is the name of the configuration) from the folder that houses the subfolder with NameOfConfig, you get an error like this: "DSC error: Cannot invoke the SendConfigurationApply method.  The sendConfigurationApply method is in progress..."
Solution: Back up and delete the subfolder named NameOfConfig.  You want to delete the .mof files. You'll need to recompile the configurations that are deleted.

How Do You List Directories Traits without Traversing into Their Contents?

Problem Scenario
You want to find out the permissions, ownership and groups associated with various subdirectories in Linux. You do not want to display the lengthy contents of these directories. How do you use the ls command to show the attributes of the directories themselves and not the contents of the directories?

Solution
From a Linux command prompt, run this command:  ls -ld /parentdirectory/

For PowerShell to list files without traversing into their contents use either of these two commands:
dir
ls

How Do You Create a New User with DSC?

Problem scenario
You are using Windows Server 2019. You want to create a new local user. You don't want the user to be a member of the local Administrators group (which allows remote logins). What do you do?

Solution

Prerequisites
i. Install DSC. If you need assistance, see this posting.
ii.a. Make sure the server has been added to its own TrustedHosts configuration settings. To do this, open PowerShell and run this:

Set-Item wsman:localhost\client\trustedhosts -Value $env:COMPUTERNAME

ii.b. Answer "Yes" to the pop up window.

Procedures

  1. Create a .ps1 file with the following content (but replace "foobar" with your desired password and replace "cooluser" with your desired password):
$ConfigData = @{
    AllNodes = @(
        @{
            NodeName=$env:COMPUTERNAME;
            PSDscAllowPlainTextPassword = $true
         }

)}


Configuration newLocalAdmin
{
    $secpasswd = ConvertTo-SecureString "foobar" -AsPlainText -Force
    $mycreds = New-Object System.Management.Automation.PSCredential ("cooluser", $secpasswd)
    
    Node $env:COMPUTERNAME
    {
        User adminUser
        {
            UserName = "Steve.J"
            Description = "This account is created using DSC"
            Password = $mycreds
            FullName = "Steve Jobs"
            PasswordNeverExpires = $true

            Ensure = 'Present'
        }
    }
}

# Run the Configuration with the -ConfigurationData parameter and use our configData as argument
newLocalAdmin -ConfigurationData $ConfigData
  1. Run the script above.
  2. Run this command (from the directory where you ran the above command as it would have created a new directory): Start-DscConfiguration -Path .\newLocalAdmin -Wait -Verbose
  3. You are done. This method was adapted from this posting.
    We think the directions above would work on most versions of Windows.

How Do You Troubleshoot Desired State Configuration Problems where Actions Are Not Working or Software Is Not Installing?

Problem scenario

You run a Start-DscConfiguration command in PowerShell like this:

Start-DscConfiguration -Path . -Wait -Verbose

You get an error message that the installation failed. The message may say something like this:

Start-DscConfiguration : The computer name was not specified and the configuration directory does not have any configuration files.

CategoryInfo : NotSpecified … ArgumentException
FullyQualifiedErrorId : System.ArgumentException, Microsoft.PowerShell.DesiredStateConfiguration.Commands.StartDscConfigurationCommand

What should you do?

Solution
Is the .mof file in the directory where you ran the above command? You could run "dir" to see if it is there. You could re-run the command to replace the "." with the directory path where the .mof file is.