Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PowerShell更改日期格式,重新启动后是否重置格式?_Powershell - Fatal编程技术网

使用PowerShell更改日期格式,重新启动后是否重置格式?

使用PowerShell更改日期格式,重新启动后是否重置格式?,powershell,Powershell,我目前正在配置一堆电脑以供工作,并创建了一个PowerShell脚本来为我完成大部分工作,但我注意到,更改电脑名称后重新启动电脑时,日期格式会重置,无法找出问题所在。脚本以管理员身份运行,下面的更改将格式更改为dd-MMM-yy,但重新启动后它将重置为M/D/YYYY # Running script as admin: if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::Get

我目前正在配置一堆电脑以供工作,并创建了一个PowerShell脚本来为我完成大部分工作,但我注意到,更改电脑名称后重新启动电脑时,日期格式会重置,无法找出问题所在。脚本以管理员身份运行,下面的更改将格式更改为
dd-MMM-yy
,但重新启动后它将重置为
M/D/YYYY

# Running script as admin:
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
    $arguments = "& '" + $MyInvocation.MyCommand.Definition + "'"
    Start-Process powershell -Verb runAs -ArgumentList $arguments
    break
}

# Set Short date format
Set-ItemProperty -Path "HKCU:\Control Panel\International" -Name sShortDate -Value dd-MMM-yy

除了安斯加·威彻斯。 如果您需要为设备上的所有用户更改它,这对我来说可以调整设备上所有用户的注册表。所有需要调整的是最后一行。在您的情况下,可能是:

function Set-RegistryValueForAllUsers {

    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$true)]
        [hashtable[]]$RegistryInstance
    )
    try {
        New-PSDrive -Name HKU -PSProvider Registry -Root Registry::HKEY_USERS | Out-Null

        $LoggedOnSids = (Get-ChildItem HKU: | where { $_.Name -match 'S-\d-\d+-(\d+-){1,14}\d+$' }).PSChildName
        Write-Verbose "Found $($LoggedOnSids.Count) logged on user SIDs"
        foreach ($sid in $LoggedOnSids) {
            Write-Verbose -Message "Loading the user registry hive for the logged on SID $sid"
            foreach ($instance in $RegistryInstance) {
              ## !!!Maakt bovenliggende map aan mocht deze niet bestaan. Wanneer bovenstaande map al bestaat zal hij deze overnieuw aanmaken en dus alle keys 
              ##  verwijderen!!! Deze variabele moet dus alleen worden beantwoord met "Nee" als er echt geen bovenliggende map is!                
              if ($env:Bovenliggend -like "Nee") {New-Item -Path "HKU:\$sid\$($instance.Path | Split-Path -Parent)" -Name ($instance.Path | Split-Path -Leaf) -Force | Out-Null }
          Set-ItemProperty -Path "HKU:\$sid\$($instance.Path)" -Name $instance.Name -Value $instance.Value -Type $instance.Type -Force
            }
        }


        Write-Verbose "Setting Active Setup registry value to apply to all other users"
        foreach ($instance in $RegistryInstance) {
            $Guid = [guid]::NewGuid().Guid
            $ActiveSetupRegParentPath = 'HKLM:\Software\Microsoft\Active Setup\Installed Components'
            New-Item -Path $ActiveSetupRegParentPath -Name $Guid -Force | Out-Null
            $ActiveSetupRegPath = "HKLM:\Software\Microsoft\Active Setup\Installed Components\$Guid"
            Write-Verbose "Using registry path '$ActiveSetupRegPath'"

            switch ($instance.Type) {
                'String' {
                    $RegValueType = 'REG_SZ'
                }
                'Dword' {
                    $RegValueType = 'REG_DWORD'
                }
                'Binary' {
                    $RegValueType = 'REG_BINARY'
                }
                'ExpandString' {
                    $RegValueType = 'REG_EXPAND_SZ'
                }
                'MultiString' {
                    $RegValueType = 'REG_MULTI_SZ'
                }
                default {
                    throw "Registry type '$($instance.Type)' not recognized"
                }
            }

            $ActiveSetupValue = "reg add `"{0}`" /v {1} /t {2} /d {3} /f" -f "HKCU\$($instance.Path)", $instance.Name, $RegValueType, $instance.Value
            Write-Verbose -Message "Active setup value is '$ActiveSetupValue'"
            Set-ItemProperty -Path $ActiveSetupRegPath -Name '(Default)' -Value 'Active Setup Test' -Force
            Set-ItemProperty -Path $ActiveSetupRegPath -Name 'Version' -Value '1' -Force
            Set-ItemProperty -Path $ActiveSetupRegPath -Name 'StubPath' -Value $ActiveSetupValue -Force
        }
    } catch {
        Write-Warning -Message $_.Exception.Message
    }
}

Set-RegistryValueForAllUsers -RegistryInstance @{'Name' = "sShortDate"; 'Type' = "String"; 'Value' = "dd-MMM-yy"; 'Path' = "\Control Panel\International"}
基本上,它进入所有已创建(包括模板)用户的UID,进入他们当前的用户注册中心并调整那里的数据。
前99%的代码只是设置Set-RegistryValueForAllUsers应该做什么,最后一行是实际执行。

我猜重新启动后,您将与其他用户登录。您的代码更改当前用户(即运行脚本的用户)的设置。要更改具有现有配置文件的其他用户的值,您需要以这些用户的身份运行代码。要更改新用户的值,您需要更改
HKEY\U users\.DEFAULT\Control Panel\International
中的设置。找不到该路径,我使用的是一台基于scala的微型PC,我需要对其进行配置。获取以下错误消息时,找不到路径“C:\Users\scala\HKEY\U Users\。默认值\Control Panel\International”默认情况下,只有
HKLM
HKCU
被定义为注册表驱动器。添加一个
HKU
New PSDrive-PSProvider Registry-Name HKU-Root HKEY\u USERS
,然后
Set ItemProperty-Path“HKU:\.Default\Control Panel\International”-Name sShortDate-Value dd MMM yy
@P4TTL这是一个注册表路径,而不是文件系统路径。没有工作的,只是在重启电脑后不断重置,我已经检查了用户帐户,它没有改变,所以不确定发生了什么事情导致它重置为默认值,除非我手动去窗口并自己更改它。您知道打开日期格式窗口的命令吗?这更改了短日期,但重新启动时又将其重置为默认日期:/n如果我无法使其工作,是否有办法在日期格式窗口打开控制面板,我可以手动更改它?因为我今天有很多事情要处理,就像考试一样。如果您转到注册表->安全,然后添加“everyone”并赋予其完全控制权。然后更改它,然后重新启动。此外,是否没有策略/防病毒程序回滚更改?是的,手动操作将是控制面板->时钟和地区->国家/地区,然后选择更改日期/时间/数字符号的选项。我认为有什么东西阻止了它内置到播放器中,由于某种原因,在我重新启动播放器并重新运行脚本后,一旦它设置好,然后重新启动,它接受日期格式并保存它…只需再点击几下,我不想在400+PC的lol上再点击几下