Is there a way to disable Action Center Notifications in Windows 10 with PowerShell?
I found a way with 2 registry keys,
DisableNotificationCenter and ToastEnabled.
New-Item -Path "HKCU:\Software\Policies\Microsoft\Windows" -Name "Explorer" -force
New-ItemProperty -Path "HKCU:\Software\Policies\Microsoft\Windows\Explorer" -Name "DisableNotificationCenter" -PropertyType "DWord" -Value 1
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\PushNotifications" -Name "ToastEnabled" -PropertyType "DWord" -Value 0
This works with PowerShell 5 on Windows 10 EN, Version 21H2.
Related
I have to translate a LINUX command into a Windows one. This is the command:
cat $(find folderName)/fileName
Searching online I found that:
cat can be translated with type
find can be translated with dir
So I tried to use something like this:
type #(dir folderName /s)/fileName
type < (dir folderName /s)/fileName
They are wrong, but I can't find any solution to combine them.
Can someone help me?
I am confident that others will provide FOR loop solutions.
This is not difficult if you use PowerShell Core or Windows PowerShell. If you are on a supported Windows system, Windows PowerShell was installed with it and is available.
While you might rightly say that this is more typing than needed in a bash/ksh script, it will run equally well on Linux, MacOS, and Windows without any modification. No 'translate' needed.
Get-Content -Path $(Get-ChildItem -Recurse -File -Path '.' -Filter 'sheet1.xml' |
Where-Object { $(Split-Path -Path $_.DirectoryName -Leaf) -eq 'worksheets' }).FullName
The amount of typing can be reduced by using aliases. While that is ok at an interactive shell, it is bad practice to encode aliases into script files.
gc $(gci -rec -file 'sheet1.xml'|?{$(Split-Path $_.DirectoryName -Leaf) -eq 'worksheets' }).FullName
If you are desperate to run this from a cmd command prompt, the following could be used.
powershell -NoLogo -NoProfile -Command ^
Get-Content -Path $(Get-ChildItem -Recurse -File -Path '.' -Filter 'sheet1.xml' ^| ^
Where-Object { $(Split-Path -Path $_.DirectoryName -Leaf) -eq 'worksheets' }).FullName
powershell -NoLogo -NoProfile -Command ^
gc $(gci -rec -file 'sheet1.xml'^|?{$(Split-Path $_.DirectoryName -Leaf) -eq 'worksheets' }).FullName
I am new to PowerShell and I need to write a script to start 3 or more windows services, in a specific order, with a set delay between them. I know how to write the script to start all of them, but I have no idea how to set the delay:
Get-Service -ComputerName cumputer_name -Name service_name1 | Stop-Service -Verbose
Get-Service -ComputerName cumputer_name -Name service_name2 | Stop-Service -Verbose
I believe you are looking for Start-Sleep.
Get-Service -ComputerName cumputer_name -Name service_name1 | Stop-Service -Verbose
Start-Sleep -Seconds 5
Get-Service -ComputerName cumputer_name -Name service_name2 | Stop-Service -Verbose
I would like to use Powershell to look up folders containing a specific word, and then look inside those for a specific file type. I'm having trouble figuring out how to do this with Powershell.
find . \
-type d -iname '*_OUTPUT' -maxdepth 2 \
-exec find {} -type f -iname '*.psd' -not -path "*.\_*" \; >> /Volumes/Path-to-output-folder/Output.csv
This is the Bash script I wrote that I run in Terminal. It works sometimes but it also crashes the SMB server connection regularly, because I'm running this on a Mac and it doesn't like the SMB server. So I want to try and do the same thing on a Windows machine because it has a reliable connection to the server.
What I'm doing here is going two folders deep of the starting directory -maxdepth 2 and looking there for any folders that end with _OUTPUT -type d -iname '*_OUTPUT'. Then, looking inside those folders for any files with the extension .psd -exec find {} -type f -iname '*.psd', ignoring hidden files which might get caught up in the search -not -path "*.\_*". Any files found are output as the full path to a CSV sheet.
I can look up folders in Powershell using -directory, and look up file types using Get-ChildItem, but I'm having trouble figuring out how to combine them in the way I did above using Bash. Is there a Powershell master out there that could help?
Let's start by breaking it down:
# Finding folders with names ending in _OUPUT
Get-ChildItem -Directory -Depth 2 -Filter *_OUTPUT
# Finding files in a folder with the .psd extension
Get-ChildItem -Path .\folder\ -File -Filter *.psd
We can combine the two with the pipeline like so:
Get-ChildItem -Directory -Depth 2 -Filter *_OUTPUT |Get-ChildItem -File -Filter *.psd
Finally, use Where-Object to exclude files starting with ._:
Get-ChildItem -Directory -Depth 2 -Filter *_OUTPUT |Get-ChildItem -File -Filter *.psd |Where Name -notlike ._*
I created a script that runs from local pc and uses invoke-command to copy files from Host-1 to host-2.
the Relevant part:
$session =New-PSSession -Computername $Thost -Credential $mycreds
Invoke-Command -Session $session -ScriptBlock {
#seting a temp drive on Host for simple approch
Remove-PSDrive -Name w -Force
New-PSDrive -Name w -PSProvider FileSystem -Root $Using:VMPath -Credential $Using:mycreds -ErrorAction Stop
Write-Host "You Chose that $Using:OSVersion will be copyed to $Using:Thost"
Copy-Item -Path "w:\$Using:OSVersion" -Destination $using:VMXPath -Recurse
Remove-PSDrive -Name w -Force -ErrorAction Stop
}
first time I run the script it runs great!
First Run of the Script
the second time it says the PSdrive doesn't exist.
Second Run Error in PowerShell
after 10 min +- the script runs again with no issues
I'm surprised it runs the first time through. It looks like the failure is on the initial Remove-PSDrive. Its failing because you've already removed the w drive.
Adopt one of these 2 models
Remove-PSDrive -Name w -ErrorAction SilentlyContinue
New-PSDrive -Name w -PSProvider FileSystem -Root c:\test
Remove-PSDrive -Name w -Force
OR
if (Test-Path -Path w:\){
Remove-PSDrive -Name w -Force
}
New-PSDrive -Name w -PSProvider FileSystem -Root c:\test
Remove-PSDrive -Name w -Force
I'd go with the second option for preference
I'm learning Git Internals https://git-scm.com/book/en/v1/Git-Internals-Git-Objects
When I try to execute this command on Windows (using cmder a better console http://cmder.net/)
find .git/objects
I get an error
What should I do instead ?
find.exe in Windows is not the equivalent of find in linux.
The equivalent of find [startpath] in PowerShell would be:
Get-ChildItem [startpath] -Name
and in cmd.exe, it would be:
dir /B [startpath]
For an equivalent of:
find foo -type f
... I use:
Get-Children foo -Name -Recurse -File | % { $_ -replace "\\", "/" }
Use the FullName attribute, otherwise it will not show the full name if the path is long:
(Get-ChildItem -Path 'C:\dist\work' -Force -Recurse -ErrorAction 'SilentlyContinue' -Filter "objects").FullName
C:\dist\work\bam-client\.git\objects
C:\dist\work\bam-extras\.git\objects
: