Powershell Get-FileMetaData not recognized - powershell

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.

Related

Use of ConvertTo-ExcelXlsx (ImportExcel) to convert .xls to .xlsx

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.

Running a PowerShell Script .PS1

I am trying to generate a MachineKey for my application using the PowerShell script found in kb2915218.
I have copied the function into notepad and saved as a .PS1 file. Now if I look at this file through explorer it is being recognised as a PowerShell file.
I then have run PowerShell and CD to the directory of my .PS1 file.
I then ran the following command:
Set-ExecutionPolicy Unrestricted
followed by:
.\Powershell-Generate-MachineKey.ps1
(the name of my script). And finally I then tried running the command
Generate-MachineKey
However I get the message:
Generate-MachineKey : The term 'Generate-MachineKey' 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
+ Generate-MachineKey
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Generate-MachineKey:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Can someone please tell me where I am going wrong here?
The script just defines a function, so if you execute it like this:
.\Powershell-Generate-MachineKey.ps1
it won't do anything, because the function isn't invoked anywhere and also isn't made available in the current context. For the latter you need to dot-source the script
. .\Powershell-Generate-MachineKey.ps1
The dot-operator basically executes the script in the current context instead of a child context. That way the definitions from the script become available in the current context, and you can invoke the function like this:
Generate-MachineKey

The term 'get-splogevent' is not recognized as the name of a cmdlet

I'm new to Sharepoint... and I'm trying to deploy a simple web part.
When I do deploy it and place it on a page, I get an error with a correlation id.
Now, I'm trying to get details about the error, and using Powershell I type...
get-splogevent | ?{$_Correlation -eq "bcce1b39-f277-4b2b-b8f8-4c113a30f193" }
But it's giving me an error....
The term 'get-splogevent' 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:15
+ get-splogevent <<<< | ?{$_Correlation -eq "bcce1b39-f277-4b2b-b8f8-4c113a30f193" }
+ CategoryInfo : ObjectNotFound: (get-splogevent:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Any ideas as to what I'm doing wrong?
Most likely you are on an ordinary Powershell session. The Sharepoint management snap-in is not being loaded, so cmdlet is not found. Take a look at an article that describes how to load the snap-in automatically to all Powershell sessions.
The snap-in is loaded manually like so,
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
I was starting the solo powershell instead of the sharepoint one. In the task bat there is "Sharepoint 2010 Management Shell", using that worked.

PowerShell issue - I have to type ./ to run bat file

I've just installed PHP & Yii Framework. It works fine, I played with CMD. But after a while I switched to PowerShell ISE. I navigated to Yii folder:
cd C:\dev\yii-1.1.9.r3527\framework
and I issued command:
yiic.bat
and I get an error:
PS C:\dev\yii-1.1.9.r3527\framework> yiic.bat
The term 'yiic.bat' 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:9
+ yiic.bat <<<<
+ CategoryInfo : ObjectNotFound: (yiic.bat:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
However when I type:
./yiic.bat
into PowerShell window, it works fine.
Is there a way to aviod typing ./ every time I run a bat file?
The framework directory you're trying to run the batch file from is evidently not in your path. When you type yiic.bat into the shell, it looks for that file in the list of directories contained in your path environment variable. See this question for information about how to set your path in powershell.
For example, if you want to be able to run batch files in the C:\dev\yii-1.1.9.r3527\framework directory, you can say $env:Path = $env:Path + ";C:\dev\yii-1.1.9.r3527\framework".
Or, as mloskot says, you can just add the current directory to your path, though that can pose a minor security risk. See e.g. this question for a bit of discussion on that.
this is an old question, but I stumbled on it looking for something else.
Powershell requires you to type .\ to run commands in the current by design.
https://blogs.technet.microsoft.com/csps/2010/06/06/introduction-to-windows-powershell-scripting/
I don't have PowerShell to try this out, but if you set the path to include current folder, this should work:
$env:Path = $env:Path + ";."

Running a function in PowerShell

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