New answers tagged

0

The PSReadLine module seems to be resetting the console properties every time when you change. Run Remove-Module PSReadLine to remove the module, console properties including cursor shape/size/colour would stay, but you will lose ReadLine features.


1

PowerShell 7 (pwsh.exe) is not Windows PowerShell (powershell.exe and powershell_ise.exe) and does not replace or upgrade Windows PowerShell. PowerShell 7 (aka PowerShell Core), is a cross-platform version solution. It is designed to run side-by-side with Windows PowerShell on Windows OS's. It will never be the default since Windows PowerShell is delivered ...


0

Killing all processes of given executable in PowerShell is done with one of: Get–Process "notepad" | Stop–Process Stop-Process -name explorer You may also use the taskkill utility.


0

What you want to do here is get the ID immediately when starting your app, then close everything that does not match. $id = (Start-Process notepad -passthru).ID Get-Process -Name notepad* | Where-Object {$_.Id -ne $id} | stop-process Above I have sampled with notepad, but you can change to your process name. You can test by opening multiple notepads first, ...


0

that is a great explanation. I am a novice. Never used PowerShell .. I tried your answer and nothing happend .. no output in PowerShell and no change. My example filename .. 2001-04-12 04.45.33.m4v My example script .. Get-ChildItem *.m4v -Recurse | ForEach-Object {$.CreationTime=[DateTime]::ParseExact($.BaseName,'yyyy-MM-dd HH.mm.ss',$null) What am I ...


0

This is a slightly cleaner solution than the accepted answer: $service = Get-Service -Name MSSQLSERVER -ErrorAction SilentlyContinue if($service -eq $null) { # Service does not exist } else { # Service does exist } In my opinion, checking it for NULL makes more sense semantically than checking for the length property. This is tested and working in ...


0

The key difference between answers here is the use of Get-WinEvent, which did not generate the failure. Credit for that has been given to @postanote. Below is my adaptation of postanote's answer. # Include quoted greatest date (e.g., '2020-06-30') from db as command line parameter Param([parameter(Mandatory=$true)] [string]$startDate ) $after = Get-Date -...


0

But.. but...but.., we are here to help you with non-working PowerShell code. which this is not. This is of course and user environment issue. What did you search for? The tool in Control Panel is called WIndwos Credential Manager and unless you cleared this, then all that is still there. There are modules that allow you to interact with the 'Windows ...


0

Following up with my comment: This is really not a PowerShell issue but and environment one base on your error. Be it because of the update, which we cannot help with troubleshooting unless one has encountered that. Similar to the data seen from the search below. 'get-eventlog : Attempted to perform an unauthorized operation' Why are you doing this? $after = ...


3

Sorry man. You are not going to be successful. Your password is not stored like you think. Only a hash of it is stored in a SAM file. The credentials file you have doesn't contain any local passwords like you hope. Credential files (CRD) only contain: Login passwords of remote computers on your LAN. Passwords of mail accounts on exchange server (stored ...


1

ScottPacker: in the end of the command, add -PassThru, and after that, you ran the powershell command you have disconnect/connect again to work. Add-VpnConnectionRoute -ConnectionName "YourVPN" -DestinationPrefix "192.168.1.0/24" -PassThru


0

Windows 10 answer: Navigate: Sound settings -> Related Settings (Sound Control Panel) -> Sounds Then click on the sound (critical beep/default beep) In "Sounds" dropdown scroll up to select "(None)" option. Apply


3

Powershell Version Based on @dbenham RegEx (Get-Content "Filepath") -replace '\B\w','.' | Set-Content "Filepath"


0

This is the default formatter in PowerShell, if you want something different, you need to alter the formatter or use the format-* cmdlets, string formatting, or create custom objects (like calculated properties, hash tables, et al) of the results and format as you'd like. 'format powershell cmdlet output' 'format powershell Format operator' The -f Format ...


1

I've found a solution using .NET. I searched and searched for the ability to list previous versions programmatically, but could not find a solution for viewing previous versions on an SMB / CIFS share. Volrest, vssadmin, alphaVss, etc. Even win32_shadowCopy failed because our target machines are netapps. Nothing worked. Then I found this post that says they ...


3

Original output: Get-Acl -Path 'C:\folder' | Select-Object -ExpandProperty Access | Select-Object -Property IdentityReference, FileSystemRights, AccessControlType, IsInherited IdentityReference FileSystemRights AccessControlType IsInherited ----------------- ---------------- -------...


12

Ctrl+H Find what: (?<![^a-z])(?<!^)[a-z] Replace with: . UNCHECK Match case CHECK Wrap around CHECK Regular expression Replace all Explanation: (?<![^a-z]) # negative lookbehind, make sure we haven't a non-letter before (?<!^) # negative lookbehind, make sure we aren't at the beginning of line [a-z] # a letter Screenshot (...


5

You just need a regular expression to identify the characters that you want to convert. That is simple, either of the following will work: \B\S, or \B\w. Now you need a tool to convert all matched characters to a . I don't use notepad++, so I can't speak to how you would to it there. But this is simple using my JREPL.BAT regular expression find/replace ...


0

To restore the correct state of Windows, there are two solutions: If you have System Restore enabled (recommended), rollback to a previous restore point. Do a Repair Install of Windows 10 with an In-place Upgrade.


1

The help function wraps the Get-Help cmdlet[1] expressly to provide interactive output paging for lengthy help texts, on Windows by default via the - bare-bones - more.com utility.[2] Simply call Get-Help rather than help to bypass the interactive paging. [1] You can see the definition (body) of this function if you execute $function:help. Note that if ...


0

How about something like this. It would only show the last 24 lines. help get-childitem | select -Last 24


1

I made a typo in a Registry edit. SSH-ing into Windows works now.


0

Use XPath to filter: ## Change child node here: $childnode = "AAA" [xml]$xml = Get-Content file.xml ## XPath: $childxpath = "/root/*/*[./child='$childnode']" ## Get node: $node = $xml.SelectSingleNode($childxpath, $null) ## Show selected node name: Write-Host $node.name In the XPath /root/*/*[./child='$childnode']: The first * matches: ...


0

I ran into this problem and was not able to fix as all the solutions lacked one important step, so I am posting my answer in very detail. Assuming you have already generated ssh-key and added its public key to your github account. npm install on Windows-10 causes a lot of problems because there are ssh-agents running from 2 different sources: Windows ...


0

If you need to use the cygwin provided bash, this worked for me: Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\OpenSSH] "DefaultShell"="C:\\cygwin64\\Cygwin.bat"


0

No need to script this, Use the built-in enterprise-ready solution for such use cases. Software Restriction Policies Technical Overview ... Software Restriction Policies | Microsoft Docs Administer Software Restriction Policies | Microsoft Docs Work with Software Restriction Policies Rules | Microsoft Docs Use Software Restriction Policies and AppLocker ...


0

Don't escape the newlines to expand command in multiple lines, use stop parsing symbol and try this: & docker.exe --% pull natverse/r-natverse & docker.exe --% run -p 127.0.0.1:8787:8787 -e DISABLE_AUTH=true -v "$HOME":/home/rstudio natverse/r-natverse


0

Just one note: Do not use PowerShell ISE to run set-executionpolicy remotesigned command as a script. It doesn't work in my case. Run it in elevated PowerShell - Please follow step-by-step recommendation provided by Pavel Chuchuva.


1

This is a script I use to create a Task which runs a script file. It is insecure because if you choose to register the task as a user, than you'll need to provide his/her's password in plain text. function Set-PowerShellScriptTask { param( $Computers, $Script, $TaskName, $Interval = 15, $User, $Password = "pwd", $Root = &...


0

I was using PowerShell ISE to write the scripts, and in spite of upgrading to PowerShell7, Powershell ISE was not upgraded, and so I was unable to use the cmdlets that I needed.


1

I've found the process creating a ton of page table entries, as well as hogging unused memory, using the steps outlined in this question: It was synergy.exe and syntool.exe from Synergy, which created lots of page table entries only 32KB long, but enough of them to take up to 3GB of RAM. I should have noted the version before uninstalling, but I rushed ...


0

Looking at the PowershellGallery page for snTeamsTest you see this text: The owner has unlisted this package. This could mean that the module is deprecated or shouldn't be used anymore. So I'm guessing the module is unsafe or not developed anymore. There is an official MS Teams Module that you can install with: Install-Module MicrosoftTeams Does that not ...


2

Firstly this... $"Microsoft-Windows-Diagnosis-DPS/Operational" ... is the wrong syntax. What you are doing here is not a use case for it. The '$' (as well as many others) has a special meaning in PowerShell and you do not use single/double quotes with plain simple strings with it. The error message means the log is truly not there or you are not ...


0

Try: &cmd /c "mysql -u user --password=pass dbname < backup.sql" You're essentially running in cmd in this case, but it's my preferred way of doing it as using < in PowerShell itself will not work (until it does one-day :P). Also, I recommend putting the path to your mysql executable into your PATH environment variable so you can simply ...


0

This is not a Powershell specific thing. It is an industry format specification. So, just search the web for each encoding individually to get the details. https://en.wikipedia.org/wiki/UTF-8 Such discussions are had for example: MicrosoftDocs/PowerShell-Docs https://github.com/MicrosoftDocs/PowerShell-Docs/issues/4021 What's the difference between UTF-8 ...


0

Windows services have a Display name, and a Service name. Fire up services.msc Find your service in the list Right-click and go to Properties Make a note of the Service name Update your PowerShell to use the correct name In the image below, you can see the Windows Biometric Service would be started by calling Start-Service -Name 'WbioSrvc' NOT Start-...


1

To extend what @Wasif_Hasan shows, know that Get-ChildItem has built-in switch parameters for a deal with Files and Folders, that one can capture to leverage in your use case. So, this can be refactored. Here is a select example... Get-ChildItem -Path 'D:\Temp' -File -Filter '*.txt' -Recurse | ForEach-Object{$($PSItem.Directory.BaseName + '_' + $PSItem....


1

What you're trying to do here is dynamic Powershell i.e. create a string that holds a Powershell command, then have Powershell run that command. You can do this with Invoke-Expression e.g.: $alertSubject = Invoke-Expression -Command "`"$((Get-Content '.\config.txt')[1])`"" Although, for maintainability, you may want to break it out into ...


2

To ensure directory names remain unchanged use this: get-childitem -recurse | Where-Object {$_.Psiscontainer -eq $false} | Rename-Item -NewName {$_.Directory.Name + "_" + $_.Name} This will filter only the files.


0

You want to avoid where statements when you can for performance reasons. To simplify a previous answer. Get-childitem -path c:\windows -exclude 'temp' | get-childitem -recurse


1

You have WSL enabled, which basically blocks you Workstation installation. https://docs.microsoft.com/en-us/windows/wsl/wsl2-faq You can either update to 2004 or disable WSL.


1

You don't need to start PowerShell twice. Loops, workflows, et al, is how you run actions multiple times. Microsoft TechNet PowerShell Loops Create a single script, call PowerShell.exe once to run the script. All PowerShell startup switches are in the help files powershell /? Example Script: 'https://server/file1.ps1','https://server/file1.ps1' | ForEach {...


0

To make Invoke-Expression 'ls $line1 (*' or Invoke-Expression "ls $line1 (*" work as intended, quote the line you want to pass to ls with different quotes, like Invoke-Expression 'ls "$line1 (*"' or Invoke-Expression "ls '$line1 (*'". Furthermore, I would like to recommend the following code optimization to you: $numbers = Get-...


0

Try this one: (You'll need Administrative Privilege) $device = Get-PnpDevice | Where-Object {$_.Class -eq "Bluetooth" -and $_.FriendlyName -eq "FriendlyDeviceName"} Disable-PnpDevice -InstanceId $device.InstanceId -Confirm:$false Start-Sleep -Seconds 10 Enable-PnpDevice -InstanceId >$device.InstanceId -Confirm:$false NOTE: THIS ...


0

You didn't tell us how you'll be deciding on the static IP for each computer, but you can surely find ways to determine that. You could have a CSV file with the hostname and the IP to set and have PowerShell read that. As Señor CMasMas said, you can use WMI to set the static IP. To give a more concrete answer, here is an example script in PowerShell: $wmi = ...


1

You can use the Windows Management Instrumentation (WMI) to accomplish this. Powershell is one of many ways to manipulate WMI so if you wanted to use c#, windows scripting host, or something else with WMI access.. they all work the same. You will first use a query to obtain the correct WMI object that allows you to tweak IP settings. You will then use the ...


0

The following is an equivalent for just read without the -s flag. What you input will be displayed, as set does not support a flag equivalent of -s, but it's a starting point security-wise, as at least your secret won't be kept in your terminal history. # set /P PASSWORD="> " > secret # echo %PASSWORD% secret


3

Apparently, Microsoft tried to design PowerShell as secure by default. Although Microsoft doesn't seem to have explicitly stated this anywhere, this restriction was probably meant to prevent users from being tricked into executing and spreading malicious scripts. There is a good description of why this could be dangerous here: PowerShell is effectively the ...


0

Deleting a local account sounds like one task, but it will at least consist of the following three steps: Delete the account from the local account database Delete the profile directory of this account Delete the account profile from the registry There might be even more steps, but I have not found any documentaion on them so far. As there are several ...


1

This sounds like a job for Group Policy software deployment. This gets around the issue of users lacking administrative rights. By publishing a package, it will make the software available to users under Control Panel (as opposed to just automatically installing it). From end users' perspectives: Setup See Microsoft's guide here (old article but still ...


Top 50 recent answers are included