Install PowerShell on Kali Linux

I tried to install PowerShell on Kali Linux Rolling by following instructions on the GitHub page as well as other articles I found online and none of them worked. I’m going to tell you what worked for me.

In the past I’ve stuck to Bash and Python for all of my scripting needs because they work cross platform. My work issued laptop runs Windows 10 and I use Git Bash to run my simple shell scripts that I use mainly to slice, dice, and reformat data, and Python for everything else. I’m a big fan of using one cross platform scripting language when possible.

Lately I’ve found a need to dive into PowerShell to be able to understand a complex script that I took over from a departing coworker. I was really surprised at how easy it is to work with XML using PowerShell after struggling to read XML with Python and xmlstarlet. Add in some Unicode and dependency problems while switching back and forth between Python 2.7 and 3.5 and I knew is was time to give PowerShell a chance. This had me thinking about starting a personal project to create a cross platform script in PowerShell to manage pentests and reporting.

Let’s get started installing PowerShell on Kali.

Edit: Updated 9/25/2018

apt -y install apt-transport-https curl gnupg
curl | apt-key add -
dpkg -i libicu57_57.1-6_amd64.deb
echo "deb [arch=amd64] stretch main" > /etc/apt/sources.list.d/powershell.list
apt-get update && apt -y install powershell

Now start PowerShell:

If you get any errors when using certain PowerShell commands, like curl for example, check your aliases. Some common aliases that work by default on Windows aren’t set here. You’ll need to either use the expanded name or set a new alias.

Using Powershell to update the hosts file on remote computers

Today I had the need to edit the hostfile on all the computers in a particular Active Directory OU.

I had previously set entries in the hosts file in a small remote office to test some system changes before rolling out the changes to everyone via DNS.

I edited my own hosts file and then ran this Powershell script to copy it to all computers in the target OU.

Import-Module ActiveDirectory
$Comps = Get-ADComputer -SearchBase ‘OU=Comp,OU=OUname,DC=domainname,DC=com’ -Filter ‘*’ | Select -ExpandProperty Name
$source = “C:WindowsSystem32driversetchosts”
$path = “WindowsSystem32driversetchosts”
$hamptonComps | foreach {Copy-Item $source -Destination \$_c$$path}

100 Days of DevOps with PowerShell

If you are a Windows admin, you need to get on the bus with Devops before you get left behind. I used to think of Devops as a Linux admin thing. With Powershell 4.0 and Windows Server 2012, Devops is here for Windows.

Why do you need Devops or Powershell on Windows systems? For starters, although some tasks may take less time to do manually than it would take the time to automate with a script, any repeatable process may benefit from automation with Powershell. If you have servers that share a common configuration, like web, email, or database servers, you can use Powershell Desired State Configuration to automate and enforce the configurations.

From the System Center Central blog:

What is PowerShell DSC?

Desired State Configuration (DSC) is a feature in PowerShell 4.0 and Windows Server 2012 R2 that helps Windows administrators manage and deploy software services’ configuration data and the environment the services run in.
DSC provides a set of PowerShell language extensions, cmdlets and a process called declarative scripting. The goal of DSC is to provide administrators with a method for maintaining consistent configuration sets across computers or devices.  You can write an expression describing a system configuration, and the system will evaluate and apply the configuration. Common use cases for PowerShell DSC include (but are not limited to):
  • Enabling or disabling server roles and features (like IIS)
  • Deploying new software
  • Deploy an IIS website (including the site content)
  • Managing registry settings
  • Running Windows PowerShell scripts
  • Managing files and directories
  • Starting, stopping, and managing processes and services
  • Managing groups and user accounts
  • Managing environment variables
  • Fixing a configuration that has drifted away from the desired state
  • Discovering the actual configuration state on a given node
The bottom line is PowerShell DSC enables IT Pros to support consistent, standardized configuration and continuous deployment, both core goals of DevOps.