Can't remove some powershell commands - powershell

I thought I'd go this sorted out in this other question but I dont seem to be able to disable the Reset-BC command.
Normally I would use
Remove-Item -force alias:Reset-BC
However I just get the following error
Remove-Item : Cannot find path 'Alias:\Reset-BC' because it does not exist.
At line:1 char:1
+ Remove-Item -force alias:\Reset-BC
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Alias:\Reset-BC:String) [Remove-Item], ItemNot
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand
Could anyone explain this or tell me how to get rid of it?
Definitely the thing that annoys me about powershell the most - it just litters your path with loads of rubbish. On occasion it also actually hides proper applications like where and sc with its stuff aswell which is even worse. I would use cmd but the lack of autocomplete is painful :(

You can test existance of Cmdlet:
If(get-item alias:Reset-BC) {Remove-Item -force alias:Reset-BC} else {'not exist'}

Related

PowerShell PackageManagement - How to uninstall a package provider?

Troubleshooting i tried uninstalling nuget. NuGetProvider-2.8.5.208.dll to be specific.
I have never worked with Power Shell before and am totally lost.
I found this question that helped me find nuget and create a command to delete it.
But I'm unable to follow through.
I did start powershell as administrator.
Here the input:
(Get-PackageProvider|where-object{$_.name -eq "nuget"}).ProviderPath|Remove-Item -force Restart-Computer
The error message:
Remove-Item : The input object cannot be bound to any parameters of the command because the command does not accept pipeline input or the input and its properties do not match any of the parameters that accept pipeline input.
and its properties do not match any of the parameters that accept pipeline input.
line:1 character:70
+ ... _.name -eq "nuget"}).ProviderPath|Remove-Item -force Restart-Computer
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (C:\Users\XXX ...GetProvider.dll:String) [Remove-Item], ParameterBindingException
+ FullyQualifiedErrorId : InputObjectNotBound,Microsoft.PowerShell.Commands.RemoveItemCommand
How can i solve this and successfully uninstall it?
Thanks for your answer!
Still no luck. Here the error:
Remove-Item : The element C:\Users\XXX\AppData\Local\PackageManagement\ProviderAssemblies\nuget\2.8.5.208
\Microsoft.PackageManagement.NuGetProvider.dll cannot be removed: Access to the path "C:\Users\XXX\AppData\Local\PackageManagement\ProviderAssemblies\nuget\2.8.5.208\Microsoft.PackageManagement.NuGetProvide
r.dll" denied.
Line:1 Character:44
+ (Get-PackageProvider NuGet).ProviderPath | Remove-Item -Force
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (C:\Users\XXX ...GetProvider.dll:FileInfo) [Remove-Item], Unauthoriz
edAccessException
+ FullyQualifiedErrorId : RemoveFileSystemItemUnAuthorizedAccess,Microsoft.PowerShell.Commands.RemoveItemCommand

Issue with New-DFSNFolderTarget cmdlet

I'm trying to automate repointing DFS folders. This is my current script:
$ft=get-dfsnfolder "\\test.dfs.domain\testpath\zzTop\*" | get-dfsnfoldertarget
$ft|% {
if ($_.targetpath -like "*blah*") {
new-dfsnfoldertarget -Path $_.path -State online -TargetPath ($_.targetpath).replace("\\blah.test.domain\testpath\zzTop","\\new.test.domain\testpath\zzTop")
}
}
I'm receiving a very weird error that is completely non-specific and makes this basically impossible to debug below:
new-dfsnfoldertarget : Can't add DFS namespace folder target "\\blah.test.domain\testpath\zzTop\2two"
At C:\Users\my_username\Desktop\ChangeDFSTargetTEST.ps1:2 char:46
+ ... *blah*") {new-dfsnfoldertarget -Path $_.path -State online -TargetP ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (MSFT_DfsNamespaceFolderTarget:ROOT\Microsoft\...aceFolderTarget) [New-DfsnFolderTarget], CimException
+ FullyQualifiedErrorId : Windows System Error 80,New-DfsnFolderTarget
new-dfsnfoldertarget : A general error occurred that is not covered by a more specific error code.
At C:\Users\my_username\Desktop\ChangeDFSTargetTEST.ps1:2 char:46
+ ... *blah*") {new-dfsnfoldertarget -Path $_.path -State online -TargetP ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (MSFT_DfsNamespaceFolderTarget:ROOT\Microsoft\...aceFolderTarget) [New-DfsnFolderTarget], CimException
+ FullyQualifiedErrorId : MI RESULT 80,New-DfsnFolderTarget
I'm running this script as admin on the box that is hosting and managing the DFS, so no issues with remote connections. I also have a script to offline these paths which works fine and also uses the "$_.targetpath -like "blah".
Also, if I run the command:
new-dfsnfoldertarget -Path $_.path -State online -TargetPath ($_.targetpath).replace("\\blah.test.domain\testpath\zzTop","\\new.test.domain\testpath\zzTop")
Replacing the variables with the strings that are fed into it automatically (so running it manually), it works fine. This is from a Server 2019 Standard box with PSVersion 5.1.17763.1490.
Any insight would be appreciated.
This won't be terribly relevant, but I realized I had set up DFS using an admin share path which is locked down almost completely so the testing I was doing was useless.
This script works fine if your DFS is healthy.

Failed to update Help for the module

PS C:\WINDOWS\system32> Update-Help
Update-Help : Failed to update Help for the module(s) 'WindowsUpdateProvider'
with UI culture(s) {en-US} : Unable to retrieve the HelpInfo XML file for UI
culture en-US. Make sure the HelpInfoUri property in the module manifest is
valid or check your network connection and then try the command again.
At line:1 char:1
+ Update-Help
+ ~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (:) [Update-Help], Exception
+ FullyQualifiedErrorId : UnableToRetrieveHelpInfoXml,Microsoft.PowerShell.Commands.UpdateHelpCommand
PS C:\WINDOWS\system32>
Please try the below, sometimes there's no XML document to update.
Update-Help -Verbose -Force -ErrorAction SilentlyContinue
Official link to Microsoft: Link
According to this link
Apparently a problem at Microsoft's end it always happens since sometimes there's no XML document to update, so for the time being use this command:
Update-Help -Verbose -Force -ErrorAction SilentlyContinue

Using a space and slash with New-Item

So I have to add this registry entry using PowerShell and sadly it has a space and a / in it. I'd like to know what the syntax is for adding this kind of entry or a new method because I'm unable to find a good answer. To be clear this needs to create a key called RC4 128/128 under the ciphers folder.
New-Item -Path "HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Ciphers" -Name RC4 128/128
This is the error I got below:
New-Item : A positional parameter cannot be found that accepts argument '128/128'.
At line:1 char:1
+ New-Item -Path "HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProvid ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-Item], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.NewItemCommand
It's not a Powershell issue, but it's an issue with the way the New-Item cmdlet is written.
Here's how you do it though:
([Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, $env:COMPUTERNAME)).CreateSubKey('SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Ciphers\RC4 128/128')
Credit: u/bhudlemeyer from reddit
It's very strange that they require you to create a key path with a space and slash because even regedit doesn't allow that.

Where is the best place to Add-PSSnapin SqlServerCmdletSnapin* and SqlServerProviderSnapin*?

I created some psm1 files and I put the following lines at the top of every psm1 file,
Set-StrictMode -Version 2
Add-PSSnapin SqlServerCmdletSnapin*
Add-PSSnapin SqlServerProviderSnapin*
However, it got warning of
WARNING: The names of some imported commands from the module 'mymodule' include unapproved verbs that might make them
less discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the Verbose
parameter. For a list of approved verbs, type Get-Verb.
And it got the following error if import the modules multiple times.
Add-PSSnapin : An item with the same key has already been added.
At line:1 char:1
+ Add-PSSnapin SqlServerCmdletSnapin*
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Add-PSSnapin], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.AddPSSnapinCommand
Add-PSSnapin : An item with the same key has already been added.
At line:2 char:1
+ Add-PSSnapin SqlServerProviderSnapin*
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Add-PSSnapin], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.AddPSSnapinCommand
Or is there a way make these snapins loaded for every users when the system is booted?
The warning simply says that authors of SqlServerCmdletSnapin and SqlServerProviderSnapin used some 'unapproved' names for their functions. But these functions will work just fine, though MS thinks they can be 'less discoverable' (when user search commands like writing "Get-" and pressing Tab-Tab-Tab... from PS console).
So you are right to put them on the top, just add -ErrorAction SilentlyContinue to get rid of the warning:
Add-PSSnapin SqlServerCmdletSnapin* -ErrorAction SilentlyContinue
Add-PSSnapin SqlServerProviderSnapin* -ErrorAction SilentlyContinue
As for loading these snapins for every user, there are several options to do that using profiles. Read Understanding the Six PowerShell Profiles article.