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:


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?

 » Read more..

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.

 » Read more..

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. 

 » Read more..

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). 

 » Read more..

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.

 » Read more..

How to Use DSC to Disable UAC Completely From Windows Server 2012

Goal:  You want to use DSC to disable UAC (User Account Control) completely.
Scenario:  You are using PowerShell version 4 and Windows Server 2012.  (The solution may work for different versions.)
You tried to use the configuration found here:

“Configuration NeverNotifyAndDisableAll
    Import-DSCResource -Module MSFT_xSystemSecurity -Name xUac

    Node localhost
        xUAC NeverNotifyAndDisableAll

 » Read more..

How to Create a New User With DSC

Goal: You are trying to use PowerShell’s DSC to create a new local user.
Problem:  An .mof file will not be created because the code will not compile.  You will get an error message like this when you try to run the .ps1 file.
“ConvertTo-MOFInstance: System.InvalidOperationException error processing property ‘Password’ OF TYPE ‘User’: Converting and storing an encrypted password as plaintext is allowed only if PSDscaAllowPlainTextPassword is set to True…

 » Read more..

How to Troubleshoot a Desired State Configuration Issue When Installing SQL Server

Goal:  You are trying to install SQL Server with DSC.  You run a .ps1 on a main DSC server.  You transfer the resulting .mof file to a Windows Server with DSC and the relevant modules for installing DSC.  The target server has the SQL Server installation media too.

Problem/Scenario: You get an error message immediately after running this command:
start-dscconfiguration SqlServerInstall -Wait -Install

“PowerShell provider MSFT_xSqlServerInstall failed to execute Set-TargetResource functionality with error message: SQL Server installation did not succeed.

 » Read more..

How Do You Create Docker Containers To Have Unique IP Addresses?

Problem scenario
How do you create Docker containers to have unique IP Addresses (but not the default 172.x.x.x type)?

(If you need help installing Docker, see this posting.)

Create new IP addresses with these commands:

ip addr add brd + dev eth0
ip addr add brd + dev eth0
ip addr add brd + dev eth0