Monday, February 19, 2018

Why Isn't This Cmdlet Working?

Last week I was working on a script that creates a list of scheduled tasks on all of our remote servers.  I wanted the script to create the list using Export-CSV.  However, everything I ran the script I would get the error:
The term 'Export-CSV' is not recognized as the name of a cmdlet

Export-CSV is not recognized!?  I have been using this for years!

I did some research and found out that some minor versions of Powershell Version 2 did not include Export-CSV.  In order to correct this it was necessary to update the version of Powershell.

How can you check the version of Powershell?  Use the following script to get the Powershell versions on all your servers:
$adServers = $()

$adServers += get-adcomputer -Filter * -Properties * -SearchBase "OU=Servers,DC=abc,DC=com" |Select-Object Name

foreach ($server in $adServers) {

 Invoke-Command -ComputerName $server.Name -ScriptBlock { $PSVersionTable.PSVersion } | export-csv -append C:\PSVersionsbyServer.csv

}

Updating Powershell is very simple but will require a reboot.  Go here to get the Powershell update.  This is version 5 and called WMF 5.  Be sure to following the prerequisites.

Again, the update will require a reboot.

Having to update the one server, so Export-CSV will work, brought up the need for my company to make sure all of our servers are running a consistent version of Powershell.  If you have a lot of servers to update, make sure you have a solid plan and communicate the changes to your user base.

I hope this information was helpful.  Good luck.

No comments:

Post a Comment