Change Windows 'List separator' using Power Shell - windows

often I have to change some Windows regional settings and I'm using PowerShell to do that, but the 'List separator' is the only field I didn't find in culture object, any clue where to find it?
My code so far:
$culture = Get-Culture
$culture.DateTimeFormat.ShortDatePattern = 'dd/MM/yy' # 'Short date' in 'Region' window.
$culture.NumberFormat.NumberDecimalSeparator = '.' # 'Decimal symbol' in 'Customize Format' window.
$culture.NumberFormat.NumberGroupSeparator = ',' # 'Digit grouping symbol' in 'Customize Format' window.
Set-Culture $culture
EDIT:
After a lot of trials and errors, I couldn't make it work using the Culture, but I could make it work using registry (very weird):
Set-ItemProperty -Path 'HKCU:\Control Panel\International' -Name sDecimal -Value '.'
Set-ItemProperty -Path 'HKCU:\Control Panel\International' -Name sThousand -Value ','
Set-ItemProperty -Path 'HKCU:\Control Panel\International' -Name sList -Value ';'

I believe you're looking for:
(Get-Culture).Textinfo.ListSeparator

Related

Inconsistency with my code, it seems to work on random occasions

I have made this code that is meant to download a picture and then set it as a wallpaper. My problem is that sometimes it works a couple of tries in a row and sometimes it doesn't work at all.(I have deleted the picture that is set to be downloaded after every single try.) I would be very happy if someone has the solution to this problem. Anyway,... here is the code:
Invoke-WebRequest https://wallpapercave.com/wp/wp69067421.jpg -o E:\skiniw.jpg
Function Set-WallPaper($Value)
{
Set-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name wallpaper -value $value
rundll32.exe user32.dll, UpdatePerUserSystemParameters
}
Set-WallPaper -value "E:\skiniw.jpg"
Try waiting for the file to be downloaded and test the file is actually there before setting it as the wallpaper:
Start-Job -Name DownloadWallpaper -ScriptBlock { Invoke-WebRequest "https://wallpapercave.com/wp/wp69067421.jpg" -o "E:\skiniw.jpg" }
Wait-Job -Name DownloadWallpaper
if (Test-Path "E:\skiniw.jpg"){
Function Set-WallPaper($Value){
Set-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name wallpaper -value $value
rundll32.exe user32.dll, UpdatePerUserSystemParameters
}
Set-WallPaper -value "E:\skiniw.jpg"
}

Unable to Set local group policy using powershell

I try to set local group policy using PowerShell. My goal is to enable
Disable changing home page settings
Below is the PowerShell script:
# Set the values as needed
$dchps_control_panel = "HKCU:\Software\Policies\Microsoft\Internet Explorer\Control Panel"
$dchps_main = "HKCU:\Software\Policies\Microsoft\Internet Explorer\Main"
$homepage = "HomePage"
$enabled = 1
$startpage = "Start Page"
$startpage_value = "www.google.com"
# Test if the Registry Key exists already
if(-not (Test-Path $dchps_control_panel) -or -not (Test-Path $dchps_main) )
{
# Create Control Panel Key to enable and Main Key
New-Item -Path $dchps_control_panel -Force
New-Item -Path $dchps_main -Force
}
# Enable Disable changing home page settings
Set-ItemProperty -Path $dchps_control_panel -Name $homepage -Value $enabled -Type DWord
#
# Set Start Page
Set-ItemProperty -Path $dchps_main -Name $startpage -Value $startpage_value -Type String
The registry keys both get created. However, when I check the "gpedit.msc" the setting still remains to disable and nothing was configured.
Thanks

Replace string in system path with Powershell

I need to change C:\Program Files (x86) in C:\Progra~2 in the system path variable. I was thinking to do this with Powershell, so I came up with the following script.
$NewPath = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).Path
$OldValue = ${Program Files (x86)}
$NewValue = "Progra~2"
$NewPath = $NewPath -replace $OldValue, $NewValue
Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH –Value $newPath
$NewPath
The output is unfortunately not what I expected.
Progra~2oProgra~2mProgra~2eProgra~21Progra~2\Progra~2oProgra~2pProgra~2mProgra~2nProgra~2\Progra~2bProgra~2iProgra~2nProgra~2;Progra~2CProgra~2:
Progra~2\Progra~2OProgra~2rProgra~2aProgra~2cProgra~2lProgra~2eProgra~2\Progra~2MProgra~2iProgra~2dProgra~2dProgra~2lProgra~2eProgra~2wProgra~2a
Can anyone help me out with this?
$OldValue = ${Program Files (x86)}
should be replaced by
$OldValue = "Program Files \(x86\)"
Backslashes \ escape the parens interpreted as a regex by -replace

Change the Show Hidden Items setting on a folder

Where is the setting to "show / hide items" on a particular folder stored?
I looking to be able to change it programmatically, hopefully in Powershell.
So try this :
$file = "c:\temp\t.txt"
# Hidde $file
Set-ItemProperty -Path $file -Name attributes -Value ([io.fileattributes]::Hidden)
# Remove Hidden if set
Set-ItemProperty -Path $file -Name attributes -Value ((Get-ItemProperty $file).attributes -bxor ([io.fileattributes]::Hidden))
I try you're code but this part doesn't work:
Set-ItemProperty -Path $file -Name attributes -Value ((Get-ItemProperty $file).attributes -bxor ([io.fileattributes]::Hidden))
I just replace "hiden" by "normal" and it's work:
Set-ItemProperty -Path $file -Name attributes -Value ([io.fileattributes]::Normal)
Thank you.

Powershell script to change the Recycling Time on Application Pool

I found the code that I think that i need to use, but the thing is that it is not working.
Import-Module WebAdministration
$appPools = Get-childItem 'IIS:\AppPools\App Pool'
Set-ItemProperty -Path $appPools -Name recycling.periodicRestart.time -Value 1.00:00:00
But I am getting this error
Set-ItemProperty : Cannot find path 'C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Modules\WebAdministration\Microsoft.IIs.PowerShell.Framework.NodeCollection' because it does not exist.
At line:3 char:1
+ Set-ItemProperty -Path $appPools -Name recycling.periodicRestart.time -Value 1.0 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\Windows\SysW....NodeCollection:String) [Set-ItemProperty], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetItemPropertyCommand
I know it isn't a path issue. This does work.
set-itemproperty -path 'D:\test\TestPS\New Text.txt' -name IsReadOnly -value $true
Any help would be great...
It is a path issue.
The object returned from Get-ChildItem 'IIS:\AppPools\App Pool' is a NodeCollection object, and when you run Set-ItemProperty -Path $appPools, $appPools is expanded to "Microsoft.IIs.PowerShell.Framework.NodeCollection" (which is not a valid path)
To change the properties of the app pool:
Set-ItemProperty -Path 'IIS:\AppPools\App Pool' -Name recycling.periodicRestart.time -Value 1.00:00:00

Resources