Trying to convert .xls file to .xlsx
by ConvertTo-ExcelXlsx function of ImportExcel module
https://github.com/dfinke/ImportExcel/
Github documentation says
Thanks to Mikkel Nordberg. He contributed a ConvertTo-ExcelXlsx. To use it, Excel needs to be installed. The function converts the older Excel file format ending in .xls to the new format ending in .xlsx.
help ConvertTo-ExcelXls returns the following as syntax:
ConvertTo-ExcelXlsx [-Path] [-Force] []
So I am trying do it like:
ConvertTo-ExcelXls -path "C:\MyFolder\MyFile.xls"
but I am getting:
ConvertTo-ExcelXls : The term 'ConvertTo-ExcelXls' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the
name, or if a path was included, verify that the path is correct and try again.
At line:2 char:1
+ ConvertTo-ExcelXls -path 'C:\MyFolder\ ...
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (ConvertTo-ExcelXls:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Well the answer is basically written in your question. The syntax is ConvertTo-ExcelXlsx but you invoked ConvertTo-ExcelXls which is not available in your shell (note the missing x at the end).
So here is the thing. Powershell adds Get- if it cannot resolve a command, so if you invoke help, it's actually Get-Help. Get-Help outputs any command that matches a part of your specified name. Get-Help -Name Excel would have given you the function as well (and probably some more). That's why you got help for ConvertTo-ExcelXlsx even though you looked up ConvertTo-ExcelXls. This makes it a littly bit tricky, but on the other hand, the help message was really helpful.
Related
I am trying to use the PowerShell command 'Get-FileMetaData' however PowerShell ISE outputs the following error:
Get-FileMetaData : The term 'Get-FileMetaData' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
At line:1 char:1
+ Get-FileMetaData E:\Test_Output
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-FileMetaData:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
The path is correct, I have also tried various existing paths. I cant find anything about what version this command requires, but using $PSVersionTable.PSVersion output states 'Major 5' so I believe I am using PS v5.
Has anyone else had issue with this command? I have found various forums mentioning its function, but cant find much on troubleshooting it.
Thanks for any help!
That is not a core PowerShell cmdlet so I would expect that to fail for most people. As far as I know that comes from the Script Gallery. You need to download that first.
So if you want that to be loaded then take that module will need to be imported either manually or automatically.
You can read more about module loading on MSDN
Using the free tool 'exiftool' I have put together to following script:
$creator = C:\Windows\exiftool.exe "-Creator" $Image.FullName
This allows $creator to be the files Creator which in the case of our production images is the same as the Author.
I am trying to implement Comment Based Help as described here with Powershell 5.1 on Windows Server 2016.
The script I am using is called blah.ps1:
<#
.DESCRIPTION
blah blah
#>
function Blahblah
{
}
In Powershell, I can load the script:
.\blah.ps1
But when I ask for help on this function using:
Get-Help Blahblah
Powershell only reports an error:
Get-Help : Get-Help could not find Blahblah in a help file in this session. To download updated help topics type: "Update-Help". To get help online, search for the help topic in the TechNet library at http://go.microsoft.com/fwlink/?LinkID=107116.
At line:1 char:1
+ Get-Help Blahblah
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (:) [Get-Help], HelpNotFoundException
+ FullyQualifiedErrorId : HelpNotFound,Microsoft.PowerShell.Commands.GetHelpCommand
I am assuming that Get-Help can be used with the custom help comments. What am I missing?
Import the script as a module instead of running it.
Import-Module .\blah.ps1
While declaring the function, including the help immediately after the function header, saving it in a module, and importing the module is probably the best way to handle it, you can make your script's help available to Get-Help by ensuring that...
the function name and the file name match (which means one function per file), and...
ensuring that the script file is in a directory that is in $env:PATH.
The help for the function can be declared before the function itself is, provided that there is no more than one blank line between the help's closing #> and the beginning of the function declaration.
See Get-Help about_Comment_Based_Help in either the PowerShell help or the linked Microsoft documentation.
I am trying to load a PowerShell module that executes a custom cmdlet function but I can't get it to load... I've applied the solutions of several previous questions, but now I'm just going in circles. Here are the specs of what I have done so far and the specific error that returns. Note that as I am new to PowerShell and programming in general, it wouldn't surprise me that my problem isn't a file path issue but a logic error in my actual function:
I created a profile function for a custom cmdlet that allows me to
open project files from two different paths:
function push-project( $project )
{
pushd ~/Documents/Visual Studio 2015/Projects/$project;
pushd ~/Documents/GitHub/$project;
}
New-Alias -Name pp -Value push-project;
I created a module by saving the function as ProfileFunctions.psm1
in the following directory:
~\Documents\WindowsPowerShell\Modules\ProfileFunctions\ProfileFunctions.psm1
To invoke the function, per its syntax, I type in pp $projectName into the PS console window, but the error that returns is standard not recognized:
pp : The term 'pp' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
pp MyFirstApp
~~
CategoryInfo : ObjectNotFound: (pp:String) [], CommandNotFoundException
FullyQualifiedErrorId : CommandNotFoundException
I copied and pasted your code into a Windows 8.1 machine I have here. It worked great (apart from the folder names not existing, since I don't have Visual Studio).
Things off the top of my head that might stop your module from working:
The file is actually called ProfileFunctions.psm1.ps1 or ProfileFunctions.psm1.txt or something.
The Modules folder is saved in someone else's documents folder, or the Public documents folder.
You've accidentally put a space in the folder name (it must be WindowsPowerShell, not Windows PowerShell).
I Think your problem is that the Alias pp is not exported from the module.
You either define the alias outside the module, as supposed to or explicitly export it from the module using.
Export-ModuleMember -Function pushproject -Alias pp
Find more details in this article Unable to Create a Powershell Alias in a script Module
My goal is to create a PowerShell script, which would open specific directories in Windows Explorer.
Some of the directories could be referenced through the environment-variables.
However I got a problem with the following command
ii %programfiles(x86)%
Execution returns the following error:
The term 'x86\' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At line:1 char:23
+ ii %programfiles\(x86\ <<<< )%
+ CategoryInfo : ObjectNotFound: (x86\:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Can you kindly explain to me, what I'm doing incorrectly here?
%variable% is batch notation. In PowerShell you have to use $env: to access environment variables.
Invoke-Item ${env:ProgramFiles(x86)}
The curly brackets are required, because without them the parentheses wouldn't be recognized as part of the variable name.
I am new to PS and have been given a script to run. The first thing I do is type in c:\powershell\ir.ps1. This seems to work. Then after defining my clients directory I am supposed to be able to just type in functions such as ir-n. This worked at the person's desk that showed me how to do it, but I get the following error:
The term 'ir-n' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name,
or if a path was included, verify that the path is correct and try again.
At line:1 char:5
+ ir-n <<<<
+ CategoryInfo : ObjectNotFound: (ir-n:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Is there something simple I can do to get it to run? I see the function in the ir.ps1 file so I know it is there.
It looks like you are running the ir.ps1 script when you should be sourcing it. I'm guessing that the ir.ps1 file is defining a function named ir-n. In that case running the script will not define the function in the script's context but not the command window. You need to source the script to get it to persist in the command window.
Try running the following
PS$> . c:\powershell\ir.ps1
After running this then try ir-n.
You probably need to dot source the script which will leave the functions it defines available in the global scope e.g.:
PS> . c:\powershell\ir.ps1