PowerShell Export-Csv can't work with UseQuotes parameter - windows

I'm trying to start this from my Powershell script:
Import-Csv -Path $filecur -Delimiter ";" | Export-Csv -Path $filenext -Delimiter ";" -NoTypeInformation -Encoding Unicode -UseQuotes Never
But after executing Powershell script command promt show the next text:
Export-Csv : A parameter cannot be found that matches parameter name 'UseQuotes'.
At C:\Users\vad\Desktop\QuatesDeleter.ps1:4 char:116
+ ... ilenext -Delimiter ";" -notypeinfo -Encoding Unicode -UseQuotes Never
+ ~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Export-Csv], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.ExportCsvCommand
How can I solve this problem?
My computer is running under Windows 7, SP1, X64, PowerShell version is 5.1.14409.1005.
In Microsoft documentation I could't find some information about this problem
Link here

It's neccesary to install PowerShell version 7.x (PowerShell Core).

Related

BrokenCimSession when stopping a scheduled task

When running the following on one of our Windows machine
$name = "My task"
Stop-ScheduledTask -TaskName $name -ErrorAction SilentlyContinue
I get this error:
Stop-ScheduledTask : Cannot connect to CIM server. The system cannot find the file specified.
+ Stop-ScheduledTask -TaskName $name -ErrorAction SilentlyContinue
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (PS_ScheduledTask:String) [Stop-ScheduledTask], CimJobException
+ FullyQualifiedErrorId : CimJob_BrokenCimSession,Stop-ScheduledTask
It does not look like a permission issus since it would look more like
Stop-ScheduledTask : Access is denied.
+ [void](Stop-ScheduledTask -TaskName $name -ErrorAction SilentlyContinue)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (PS_ScheduledTask:Root/Microsoft/...p_ScheduledTask) [Stop-Schedul
edTask], CimException
+ FullyQualifiedErrorId : HRESULT 0x80070005,Stop-ScheduledTask
A couple of facts to help:
I'm not running this remotely
Get-ScheduledTask will throw the same CimJob_BrokenCimSession error
Are you an administrator on the system? The error says permission denied (Misread OP)
When troubleshooting, it generally helps if you don't have -erroraction silentlycontinue if you actually want to see what's erroring. Obviously, you don't have it in a try/catch block, so you can see the error, but having the option to suppress errors doesn't make sense here.
More suggestions:
Are you running this command remotely? If you're running it against many servers, check your server list.
What happens if you get all the tasks, e.g. $tasks = get-scheduledtask, then reference the one you want with $tasks | where taskname -like "whatever" | stop-scheduledtask (or its index number in the array, e.g. $tasks[5]).
I didn't get any errors when I ran the preceding command against tasks that weren't running, but perhaps it does return an error in some cases if the task isn't in the running state.

PowerShell command to get installed application/software version

I need to read product version from control panel for specific application. I'm using this command till now.
Get-WmiObject Win32_Product -Filter "Name like 'ISASmaartHub'" | Select-Object -ExpandProperty
after upgrading my system to Windows 11 it is throwing this exception -
Select-Object : Missing an argument for parameter 'ExpandProperty'. Specify a parameter of type 'System.String' and try again.
At line:1 char:82
+ ... -Filter "Name like 'ISASmaartHub'" | Select-Object -ExpandProperty
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Select-Object], ParameterBindingException
+ FullyQualifiedErrorId : MissingArgument,Microsoft.PowerShell.Commands.SelectObjectCommand
Can anyone please suggest which command I should use to read the version of an application on Windows 11 system.
Thanks in advance!
Prefer using Get-CimInstance over Get-WmiObject for new applications, as WMI is being deprecated.
For WMI\CIM, operator LIKE uses WQL language and should have a % sign as a mark for Any symbols. WQL Like Syntax
Select -ExpandProperty smth means from this big object select only value of smth property. This means, property name MUST present.
Working Example for product named 1C:
Get-CimInstance -Filter 'NAME LIKE "%1C%"' -ClassName 'Win32_Product' |
Select -ExpandProperty 'Version'

use PowerShell to save file in Visual Studio

Using Powershell from Package Manager Console I can open and close file:
$DTE.ExecuteCommand(“File.OpenFile”, $file)
$DTE.ExecuteCommand(“File.Close”)
But when I try to save it:
$DTE.ExecuteCommand(“File.Save”, $file)
or
$DTE.ExecuteCommand(“File.Save”)
I get error:
PM> $DTE.ExecuteCommand(“File.Save”) Command "File.Save" is not valid.
At line:1 char:1
+ $DTE.ExecuteCommand(“File.Save”)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
How I can save it?
Actually I want to save it in other encoding:
You can save the file with
$DTE.ExecuteCommand("File.SaveSelectedItems")
There is also
$DTE.ExecuteCommand("File.SaveAll")
If you're doing this only to change the file's encoding however, I would suggest simply running the following PowerShell code that doesn't require $DTE and Visual Studio at all.
$content = Get-Content -Path $file -Encoding String
Set-Content -Value $content -Path $file -Encoding UTF8

Why doesn't "Set-Item" work on Windows 7 PowerShell?

I am trying to install Windows 10 IoT on my Raspberry Pi 2. The PowerShell documentation tells me to put in this:
Set-Item WSMan:\localhost\Client\TrustedHosts -Value <minwinpc>
However, when I put it into my Windows 7 PowerShell, this comes out:
At line:1 char:54
+ Set-Item WSMan:\localhost\Client\TrustedHosts -Value <minwinpc>
+ ~
The '<' operator is reserved for future use.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : RedirectionNotSupported
How do I fix this?
You need to use quotes rather than < > around the name of the device (minwinpc)
Set-Item WSMan:\localhost\Client\TrustedHosts -Value 'minwinpc'

search for a folder buried in a folder and move the folder to a new destination

I want to move the Favorites folder from a folder that changes its folder guid daily from Appsense.
Text between quotes changes.
C:\appsensevirtual\S-1-5-21-220523388-2000478354-839522115-60875\'{647CFC75-E4C0-4F13-9888-C37BA083416C}'\_Microsoft Office 2010
I have found this but it never copies to the H: (Homedrive).
Get-ChildItem "C:\Appsensevirtual" -Recurse -Filter "Favorites*" -Directory |
Move-Item -Destination "H:\Favorites"
If i run I get this in an Powershell Administrator Window (powershell 2)
PS C:\temp> .\favorites.ps1
Get-ChildItem : A parameter cannot be found that matches parameter name 'Directory'.
At C:\temp\favorites.ps1:1 char:76
+ Get-ChildItem "C:\Appsensevirtual" -Recurse -Filter "Favorites*" -Directory <<<< | Move-Item -Destination "H:\Favorites"
+ CategoryInfo : InvalidArgument: (:) [Get-ChildItem], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
You solution is:
Remove -Directory from your command, and add -Force which will parse system & hidden folders.
Get-ChildItem "C:\Appsensevirtual" -Recurse -Filter "Favorites*" -Force |
Move-Item -Destination "H:\Favorites"

Resources