I'm trying to update a (root) certificate's friendly name through PowerShell.
The certificate I'm trying to update is highlighted in the screenshot below (taken from certmgr.msc):
Here's the PowerShell code (largely taken from here):
Set-Location cert:
cd .\CurrentUser\Root
$cert = gci .\02FAF3E291435468607857694DF5E45B68851868
$cert.FriendlyName = "UserTrust CA"
(I've verified the thumbprint with the certificate properties in certmgr.msc to make sure it's the same certificate).
The last line will result in the following error:
Exception setting "FriendlyName": "Access is denied.
"
At line:1 char:7
+ $cert. <<<< FriendlyName = "UserTrust CA"
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
I've tried the following things so far:
Running PowerShell as administrator
Changing the execution policy using: Set-ExecutionPolicy Unrestricted
Other information:
PowerShell version is 2.0 (running on Windows 7 Enterprise x64)
I'm running the x64 version of PS
DEP and UAC are disabled
My account is part of the Administrators group
I'm a complete PowerShell n00b ;-)
PS version output:
$PSVersionTable.PSVersion
Major Minor Build Revision
----- ----- ----- --------
2 0 -1 -1
You need to update your version of Powershell to 3.0 or 4.0.
See Get-ChildItem for Certificate
I have Powershell 4.0 and I was able to change the FriendlyName without problems. This was visible in certmgr.msc after a restart.
You can download Powershell 4.0 here.
If you are a Powershell beginner it's probably better to use Get-ChildItem instead of gci for improved readability. Also, cd is an alias of Set-Location so it's better to choose one or the other in your script to avoid confusion.
Related
I need a way to reliably remove all Appx Package from a system that start with a given string. On most systems the following works:
Get-AppxPackage -all MyApp* | Remove-AppxPackage -AllUsers
However for two systems I get the following:
PS C:\Users\Administrator> Get-AppxPackage -all CDI* | Remove-AppxPackage -AllUsers
Remove-AppxPackage : A parameter cannot be found that matches parameter name 'AllUsers'.
At line:1 char:48
+ Get-AppxPackage -all CDI* | Remove-AppxPackage -AllUsers
+ ~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Remove-AppxPackage], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.Windows.Appx.PackageManager.Commands.RemoveAppxPackageCommand
This basically says AllUSers is invalid, but this contradicts the Get-Help output:
Get-Help Remove-AppxPackage -Parameter AllUsers
-AllUsers [<SwitchParameter>]
{{Fill AllUsers Description}}
Required? false
Position? named
Default value False
Accept pipeline input? False
Accept wildcard characters? false
Is there a Path issue or another way to remove the Appx package for everyone?
Update #1: Version info
Here is the version info for the command:
PS C:\Users\Administrator> Get-Command Remove-AppxPackage
CommandType Name Version Source
----------- ---- ------- ------
Function Remove-AppxPackage 1.0 Appx
And the OS
> [System.Environment]::OSVersion.Version
Major Minor Build Revision
----- ----- ----- --------
10 0 14393 0
Update #2
Module version output
PS > Get-Module -ListAvailable Appx
Directory: C:\Windows\system32\WindowsPowerShell\v1.0\Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 2.0.0.0 Appx {Add-AppxPackage, Get-AppxPackage, Get-AppxPackageManifest...
Is there any way to produce the same effect as the AllUsers Switch when i don't have it (even though the documentation says i should)
Remove-AppxPackage has an -AllUsers switch only in recent versions of Windows (both desktop and server editions).
On the linked page, browsing the version-specific doc pages (via the dropdown list of versions above the list of topics on the left) shows that Windows Server 2016 PowerShell and Windows 10 and Windows Sever 2019 PowerShell are the earliest versions that document -AllUsers.
As you've stated later, you're using Windows Server 2016, and the version number indicates a recent release, so -AllUsers should work. For instance, on my recent Windows 10 release (release ID 21H2, build 19044; Windows 10 has the same foundation as Windows Server 2016), -AllUsers is present. A notable difference is that the AppX module version is 2.0.1.0 on my machine, compared to 1.0 on yours, which may explain the difference:
Your error message indeed implies that the cmdlet itself lacks an -AllUsers parameter - despite what the Get-Help cmdlet may report (the information isn't guaranteed to be in sync).
If you want to know whether a given command truly supports a given parameter, use Get-Command -Syntax, which directly consults the command's definition; in this case: (Get-Command -Syntax Remove-AppxPackage) -match '-AllUsers'
A simpler alternative is to try to tab-complete the parameter name: if nothing happens, the parameter doesn't exist.
Potential solutions:
Use Get-Module -ListAvailable AppX to see if you accidentally have multiple versions of the AppX module installed (with an obsolete one shadowing the platform-appropriate one), and if so, remove all but the most recent one (highest version number).
Otherwise, you can try to manually copy the module from a recent Windows 10 / Windows Server 2019 or a Windows Server 2022 machine - but you'll have to see if that actually works.
Unfortunately, the Appx module is not available in the PowerShell Gallery, so you cannot simply install the latest version with Install-Module.
The need for doing this would imply that the docs for Windows Server 2016 are incorrect.
The cmdlet, like many others also, would require you to elevate the PowerShell to have admin permissions if you want to affect other users.
When trying to run Set-Date in my powershell script it fails because it claims to require more permissions. I have added the groups Users and even Everyone to the Adjust system time Local Security Policy. Of course I could run it elevated to admin, but I'm trying to avoid that. What's extra odd is that this script has worked fine so far on some machines.
Powershell version is 5.1, windows version is 10 Enterprise 2016 (v1607)
The error message:
PS > Set-Date "2021-06-07T10:00"
Set-Date : Klienten har ikke nødvendig tilgangsnivå
At line:1 char:1
+ Set-Date "2021-06-07T10:00"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Set-Date], Win32Exception
+ FullyQualifiedErrorId : System.ComponentModel.Win32Exception,Microsoft.PowerShell.Commands.SetDateCommand
Though I do not fully understand why, it works when you disable the policy User Account Control: Run all administrators in Admin Approval Mode.
This is a common error that is not solved by the common solutions I have found on the internet.
Unable to run Get-PsRepository, Install-Module, and related (OneGet?) commands without them throwing the "Unable to find module providers (PowerShellGet)" error. This appears to be an issue with the NuGet packagemanager module but I do not know how to recover. The package provider installed appears valid
Symptom patterns:
C:> [Net.ServicePointManager]::SecurityProtocol
Tls12
Get-PSRepository
PackageManagement\Get-PackageSource : Unable to find module providers (PowerShellGet).
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:4496 char:31
+ ... ckageSources = PackageManagement\Get-PackageSource #PSBoundParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (Microsoft.Power...etPackageSource:GetPackageSource) [Get-PackageSource
], Exception
+ FullyQualifiedErrorId : UnknownProviders,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageSource
Register-PSRepository -Default -Verbose
VERBOSE: PowerShell meta provider initialization failed.
VERBOSE: No match was found for the specified search criteria and provider name 'PowerShellGet'. Try
'Get-PackageProvider -ListAvailable' to see if the provider exists on the system.
PackageManagement\Register-PackageSource : Unable to find module providers (PowerShellGet).
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:4211 char:17
+ ... $null = PackageManagement\Register-PackageSource #PSBoundParamete ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (Microsoft.Power...erPackageSource:RegisterPackageSource) [Register-Pac
kageSource], Exception
+ FullyQualifiedErrorId : UnknownProviders,Microsoft.PowerShell.PackageManagement.Cmdlets.RegisterPackageSource
Install-Module PowerShellGet -Force
PackageManagement\Install-Package : Unable to find module providers (PowerShellGet).
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1809 char:21
+ ... $null = PackageManagement\Install-Package #PSBoundParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Exception
+ FullyQualifiedErrorId : UnknownProviders,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
Facts:
Windows 10 (1903)
Powershell 5.1.18362.1171
Running PowerShell as Administrator
Not behind a proxy
Have access to https://www.powershellgallery.com/api/v2
Have access to nuget.org
`[Net.ServicePointManager]::SecurityProtocol = Tls12
FIPS is disabled (HKLM\System\CurrentControlSet\Control\Lsa\FIPSAlgorithmPolicy\Enabled DWORD=0)
Get-PackageProvider shows only NuGet 2.8.5.208
PowerShellGet version is 1.0.0.1 ; when trying force a sxs install with Install-Module PowerShellGet -Force I get the same: PackageManagement\Install-Package : Unable to find module providers (PowerShellGet).
We encountered the same problem. Found this thread without a solution. But I dug a bit further and on the computer that had this problem we found version 1.4.7 of PackageManagement installed.
After removing this folder everything started working normally. I have not found how this thing got installed. Seems like a legit powershell module from Microsoft but it's interacting with the 'normal' PowershellGet module and seems to break it.
For us it was located in the %USERPROFILE%/documents/WindowsPowershell/Modules.
Also worth nothing that this %USERPROFILE% was a corporate OneDrive.
Edit: Microsoft have fixed this issue: https://github.com/PowerShell/vscode-powershell/issues/3432
Not enough Rep to comment.
I ended up in the same situation. A Windows 10 1909 machine, with
%USERPROFILE%/document being a corporate OneDrive. Moving
PackageManagement out of /WindowsPowerShell/ changed
Get-PSRepository's output from nothing to PSGallery. Thanks! – tmcg
Mar 1 at 21:35 This was exactly the same issue. I suspect this is
because PowerShell 7 dumped it into this location (possibly Visual
Studio Code when it prompt to update?) – aolszowka Mar 1 at 22:09
I encountered the same issue with packagemanagement in %USERPROFILE%/documents on my personal profile. The file dates matched when I installed VScode and the Powershell Extensions on this new machine.
Removing the folder from modules corrected the issue for the time being.
In addition to removing %USERPROFILE%/Documents/WindowsPowershell/Modules folder, I also found that putting the package manger locally helped powershell.exe -NoLogo -NoProfile -Command 'Save-Module PackageManagement -MinimumVersion 1.4.7 -LiteralPath ""C:\Program Files\WindowsPowerShell\Modules\""' thanks to itsho here https://github.com/PowerShell/vscode-powershell/issues/2824#issuecomment-750902181
The cause is due to the %USERPROFILE%/Documents folder being on a OneDrive and module-install keeps installing the PackageManagement module to user documents by default ignoring PSModulePath, even had the OneDrive location removed/changed.
This my module path from running PS inside vscode identifying info removed:
$env:PSModulePath -split ';'
C:\Users\{myUsername}\OneDrive - {myCompanyName}\{company}\Documents\WindowsPowerShell\Modules
C:\Program Files\WindowsPowerShell\Modules
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
There are more things that can be done to fix this from happening again discussed here https://github.com/PowerShell/PowerShell/issues/15552#issuecomment-1002708799
Like setting the documents folder to local and off OneDrive like shown here https://support.microsoft.com/en-us/topic/configuration-of-the-my-documents-folder-dfd9a90d-8f80-18d6-e7cc-f1566fc3b10b
I followed these steps for now.
In explorer to the left under quick access right click Documents, and then click Properties.
Change to the location tab in the configuration box and type the new path to the Documents folder, I used the local one
Click No so the existing files do not move and still can be accessed by going into OneDrive. I also added another quick access folder for my OneDrive location, but that is up to you.
Note: This effects other programs as well like the default save location for PowerPoint. You'll need to be mindful that you don't save something local thinking it will be backed up to OneDrive.
My module paths after the change:
$env:PSModulePath -split ';'
C:\Users\{myUsername}\Documents\WindowsPowerShell\Modules
C:\Program Files\WindowsPowerShell\Modules
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
Another workaround could be to have OneDrive keep the files local.
Navigate to %USERPROFILE%/Documents
Right click WindowsPowershell and select "Always keep on this device".
I haven't been able to test this one, but it might be the least impactful way to address this.
I am following the Chocolately Install steps (Windows 7), but have run into a couple of problems.
Firstly, I've opened Command Prompt (opening it with Run as administrator), but when trying to execute Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')), I get this error:
Uncaught SyntaxError: Unexpected identifier
..with the https: part of my command highlighted.
Further, when I try to execute Get-ExecutionPolicy, it results in:
Uncaught ReferenceError: Get is not defined
Any ideas what could be wrong?
* UPDATE *
When I try the same command in PowerShell, I get this error:
PS C:\Users\mylogin> Set-ExecutionPolicy Bypass -Scope Process -Force;
[System.Net.ServicePointManager]::SecurityProtoc ol =
[System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex
((New-Object System.Net.WebClient).DownloadString
('https://chocolatey.org/install.ps1')) Exception setting
"SecurityProtocol": "Cannot convert value "3312" to type
"System.Net.SecurityProtocolType" due to inv alid enumeration values.
Specify one of the following enumeration values and try again. The
possible enumeration values are "Ssl3, Tls"." At line:1 char:85
+ Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]:: <<<< SecurityProtocol = [System.
Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object
System.Net.WebClient).DownloadString('https://ch
ocolatey.org/install.ps1'))
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
Exception calling "DownloadString" with "1" argument(s): "The
underlying connection was closed: An unexpected error occ urred on a
send." At line:1 char:219
+ Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.Se
rvicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object
System.Net.WebClient).DownloadString <<<< ('https://ch
ocolatey.org/install.ps1'))
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Download chocolatey latest version from Chocolatey.org
Rename file extension to .zip
Extract the file
Open PowerShell
Open elevated PowerShell calling:
Start-Process powershell -Verb runAs
Go to the tools folder in the location where you extracted Chocolatey
Call: & .\chocolateyInstall.ps1 to allow Chocolatey to install
Add a path to the choco location to system environment PATH:
C:\ProgramData\chocolatey\bin
Restart your consoles, and VS Code (if you use one)
Chocolatey.org requires TLS 1.2 to be able to connect. This error indicates that you don't have support for that installed:
System.Net.WebClient).DownloadString ('https://chocolatey.org/install.ps1')) Exception setting "SecurityProtocol": "Cannot convert value "3312" to type "System.Net.SecurityProtocolType" due to inv alid enumeration values. Specify one of the following enumeration values and try again. The possible enumeration values are "Ssl3, Tls"
The section from the blog post I linked to earlier should help:
If you find yourself provisioning machines such as Windows 7, Windows Server 2008, or older, you will find that those machines will not be able to communicate with the Chocolatey Community Repository after we implement this change. For those instances, you will need to use alternative installation methods for Chocolatey. We strongly recommend using the offline Chocolatey installation as it provides the most flexibility and reliability.
On the Chocolatey install page the requirements are listed:
Windows 7+ / Windows Server 2003+
PowerShell v2+ (minimum is v3 for install from this website due to TLS 1.2 requirement)
.NET Framework 4+ (the installation will attempt to install .NET 4.0 if you do not have it installed)(minimum is 4.5 for install from this website due to TLS 1.2 requirement)
My suggestion would be to fully patch your Windows 7 system, install .NET 4.5 and then try it. Remember Windows 7 has been out of support since January this year.
Description: I am running/executing powershell from a ruby script (.rb) file
exec "powershell.exe Import-Module PSWindowsUpdate"
I downloaded the PSWindowsUpdate module from "Windows Update PowerShell Module" and copied the files to the following location:
%WINDIR%\System32\WindowsPowerShell\v1.0\Modules
When I run the above I get the following error:
Z:\Desktop>ruby windows_patch.rb
Import-Module : The specified module 'PSWindowsUpdate' was not loaded because
no valid module file was found in any module directory.At line:1 char:1
+ Import-Module PSWindowsUpdate
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (PSWindowsUpdate:String) [I
mport-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Comm
ands.ImportModuleCommand
However, when I run this via Powershell it runs fine and dandy.
I'm using:
Windows 7 x64
PowerShell v4
Ruby v2.1.5
The result of exec "powershell.exe ruby -e 'puts $:'" is:
C:/Ruby21/lib/ruby/site_ruby/2.1.0
C:/Ruby21/lib/ruby/site_ruby/2.1.0/i386-msvcrt
C:/Ruby21/lib/ruby/site_ruby
C:/Ruby21/lib/ruby/vendor_ruby/2.1.0
C:/Ruby21/lib/ruby/vendor_ruby/2.1.0/i386-msvcrt
C:/Ruby21/lib/ruby/vendor_ruby
C:/Ruby21/lib/ruby/2.1.0
C:/Ruby21/lib/ruby/2.1.0/i386-mingw32
I ran powershell.exe $env:PSModulePath which gave me:
\vmware-host\Shared Folders\Documents\WindowsPowerShell\Modules;C:\Program Files (x86)\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\M
odules\
I then copied the folder to C:\Program Files (x86)\WindowsPowerShell\Modules
I then got:
Import-Module : The specified module 'PSWindowsUpdate' was not loaded because
no valid module file was found in any module directory.At line:1 char:39
Next, I then ran:
PS C:\Users\Justin.Schuhmann> Set-ExecutionPolicy -Scope LocalMachine
cmdlet Set-ExecutionPolicy at command pipeline position 1
Supply values for the following parameters:
ExecutionPolicy: Unrestricted
Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose
you to the security risks described in the about_Execution_Policies help topic at
http://go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"):
This solved the issue, I don't have a permanent solution yet as this is only temporary. When setting