Windows Server 2022 をPowerShellを使って設定しよう

PowerShell
PowerShellWindows Server 2022

テンプレート展開するほどじゃないけど、構築対象のサーバ数がそれなりにある。そんな時、コマンドをコピペするだけで設定できると構築も素早く終わっていいですよね。ここでは、Windows Server 2022 をPowerShellを使って設定する方法について記載します。

Windows Server 2022 にインストールされているPowerShellのバージョン($PSVersionTable)は、5.1となります。管理用PowerShellの説明はこちらのサイトに詳細が記載されています。

1.「サーバーマネージャー」画面の自動起動停止

「サーバーマネージャー」画面をコマンドで起動停止するには、ローカルグループポリシーの設定変更をコマンドで行う必要があるのですが、Microsoft社が提供している「ローカル グループ ポリシー オブジェクト (LGPO) ツール」をインストールする必要があるようです。事前にローカルグループポリシーをGUIで設定し、その設定をファイル出力したものを用いて、設定する形ですね。

Microsoft セキュリティ コンプライアンス Toolkit 1.0 ガイド – Windows security | Microsoft Docs

今は、GUIで実施したほうがよさそうです。

2.ホスト名変更

1.ホスト名を変更するPowerShellコマンド

$Hostname  = "WIN2022AD2"
Rename-Computer -NewName ${Hostname}

出力結果

PS C:\Users\Administrator> $Hostname  = "WIN2022AD2"
PS C:\Users\Administrator> Rename-Computer -NewName ${Hostname}
警告: 変更は、コンピューター WIN-LHLGAKUQ9HH の再起動後に有効になります。
PS C:\Users\Administrator>

再起動は、この後のネットワーク設定を行なった後で大丈夫です。

3.ネットワーク設定

1.IPアドレス設定を表示するPowerShellコマンド

Get-NetIPConfiguration

出力結果

PS C:\Users\Administrator> Get-NetIPConfiguration


InterfaceAlias       : Ethernet1
InterfaceIndex       : 5
InterfaceDescription : Intel(R) 82574L Gigabit Network Connection
NetProfile.Name      : 識別されていないネットワーク
IPv4Address          : 172.16.169.157
IPv6DefaultGateway   :
IPv4DefaultGateway   :
DNSServer            : 172.16.169.1

InterfaceAlias       : Ethernet0
InterfaceIndex       : 7
InterfaceDescription : Intel(R) 82574L Gigabit Network Connection #2
NetProfile.Name      : ネットワーク
IPv4Address          : 192.168.10.7
IPv6DefaultGateway   : fe80::6ee4:daff:fec0:a570
IPv4DefaultGateway   : 192.168.10.1
DNSServer            : 192.168.10.1



PS C:\Users\Administrator>

2.IPアドレスを設定するPowerShellコマンド

#ネットワークアダプタ1のIPアドレス設定
$InterfaceName1 = "Ethernet0"
$IPAddress1 = "192.168.10.202"
$NetMaskLength1 = "24"
$Gateway1 = "192.168.10.1"
New-NetIPAddress -InterfaceAlias ${InterfaceName1} -AddressFamily IPv4 -IPAddress ${IPAddress1} -PrefixLength ${NetMaskLength1} -DefaultGateway ${Gateway1}
#ネットワークアダプタ2のIPアドレス設定
$InterfaceName2 = "Ethernet1"
$IPAddress2 = "192.168.20.202"
$NetMaskLength2 = "24"
New-NetIPAddress -InterfaceAlias ${InterfaceName2} -AddressFamily IPv4 -IPAddress ${IPAddress2} -PrefixLength ${NetMaskLength2}

出力結果

PS C:\Users\Administrator> $InterfaceName1 = "Ethernet0"
PS C:\Users\Administrator> $IPAddress1 = "192.168.10.202"
PS C:\Users\Administrator> $NetMaskLength1 = "24"
PS C:\Users\Administrator> $Gateway1 = "192.168.10.1"
PS C:\Users\Administrator> New-NetIPAddress -InterfaceAlias ${InterfaceName1} -AddressFamily IPv4 -IPAddress ${IPAddress1} -PrefixLength ${NetMaskLength1} -DefaultGateway ${Gateway1}


IPAddress         : 192.168.10.202
InterfaceIndex    : 7
InterfaceAlias    : Ethernet0
AddressFamily     : IPv4
Type              : Unicast
PrefixLength      : 24
PrefixOrigin      : Manual
SuffixOrigin      : Manual
AddressState      : Tentative
ValidLifetime     : Infinite ([TimeSpan]::MaxValue)
PreferredLifetime : Infinite ([TimeSpan]::MaxValue)
SkipAsSource      : False
PolicyStore       : ActiveStore

IPAddress         : 192.168.10.202
InterfaceIndex    : 7
InterfaceAlias    : Ethernet0
AddressFamily     : IPv4
Type              : Unicast
PrefixLength      : 24
PrefixOrigin      : Manual
SuffixOrigin      : Manual
AddressState      : Invalid
ValidLifetime     : Infinite ([TimeSpan]::MaxValue)
PreferredLifetime : Infinite ([TimeSpan]::MaxValue)
SkipAsSource      : False
PolicyStore       : PersistentStore



PS C:\Users\Administrator>PS C:\Users\Administrator> $InterfaceName2 = "Ethernet1"
PS C:\Users\Administrator> $IPAddress2 = "192.168.20.202"
PS C:\Users\Administrator> $NetMaskLength2 = "24"
PS C:\Users\Administrator> New-NetIPAddress -InterfaceAlias ${InterfaceName2} -AddressFamily IPv4 -IPAddress ${IPAddress2} -PrefixLength ${NetMaskLength2}


IPAddress         : 192.168.20.202
InterfaceIndex    : 5
InterfaceAlias    : Ethernet1
AddressFamily     : IPv4
Type              : Unicast
PrefixLength      : 24
PrefixOrigin      : Manual
SuffixOrigin      : Manual
AddressState      : Tentative
ValidLifetime     : Infinite ([TimeSpan]::MaxValue)
PreferredLifetime : Infinite ([TimeSpan]::MaxValue)
SkipAsSource      : False
PolicyStore       : ActiveStore

IPAddress         : 192.168.20.202
InterfaceIndex    : 5
InterfaceAlias    : Ethernet1
AddressFamily     : IPv4
Type              : Unicast
PrefixLength      : 24
PrefixOrigin      : Manual
SuffixOrigin      : Manual
AddressState      : Invalid
ValidLifetime     : Infinite ([TimeSpan]::MaxValue)
PreferredLifetime : Infinite ([TimeSpan]::MaxValue)
SkipAsSource      : False
PolicyStore       : PersistentStore



PS C:\Users\Administrator>

3.DNSClientServerアドレス設定するPowerShellコマンド

#ネットワークアダプタ1のDNSClientServerのIPアドレス設定
$InterfaceName1 = "Ethernet0"
$DNSServerAddress1 = "192.168.10.1"
Set-DnsClientServerAddress -InterfaceAlias ${InterfaceName1} -ServerAddresses ${DNSServerAddress1} -PassThru
$InterfaceName1 = "Ethernet0"
$DNSServerAddress1 = "192.168.10.1"
$DNSServerAddress2 = "192.168.10.2"
Set-DnsClientServerAddress -InterfaceAlias ${InterfaceName1} -ServerAddresses ${DNSServerAddress1},${DNSServerAddress2} -PassThru

出力結果

PS C:\Users\Administrator> $InterfaceName1 = "Ethernet0"
PS C:\Users\Administrator> $DNSServerAddress1 = "192.168.10.1"
PS C:\Users\Administrator> Set-DnsClientServerAddress -InterfaceAlias ${InterfaceName1} -ServerAddresses ${DNSServerAddress1} -PassThru

InterfaceAlias               Interface Address ServerAddresses
                             Index     Family
--------------               --------- ------- ---------------
Ethernet0                            7 IPv4    {192.168.10.1}
Ethernet0                            7 IPv6    {}


PS C:\Users\Administrator>

4.IPv6無効化設定するPowerShellコマンド

#ネットワークアダプタ1のIPv6無効化設定
$InterfaceName1 = "Ethernet0"
Disable-NetAdapterBinding -Name ${InterfaceName1} -ComponentID ms_tcpip6 -PassThru
#ネットワークアダプタ2のIPv6無効化設定
$InterfaceName2 = "Ethernet1"
Disable-NetAdapterBinding -Name ${InterfaceName2} -ComponentID ms_tcpip6 -PassThru

出力結果

PS C:\Users\Administrator> $InterfaceName1 = "Ethernet0"
PS C:\Users\Administrator> Disable-NetAdapterBinding -Name ${InterfaceName1} -ComponentID ms_tcpip6 -PassThru

Name                           DisplayName                                        ComponentID          Enabled
----                           -----------                                        -----------          -------
Ethernet0                      インターネット プロトコル バージョン 6 (TCP/IPv6)  ms_tcpip6            False


PS C:\Users\Administrator> $InterfaceName2 = "Ethernet1"
PS C:\Users\Administrator> Disable-NetAdapterBinding -Name ${InterfaceName2} -ComponentID ms_tcpip6 -PassThru

Name                           DisplayName                                        ComponentID          Enabled
----                           -----------                                        -----------          -------
Ethernet1                      インターネット プロトコル バージョン 6 (TCP/IPv6)  ms_tcpip6            False


PS C:\Users\Administrator>

5.ネットワークアダプタの名称の変更するPowerShellコマンド

#ネットワークアダプタ1の名称変更
$InterfaceName1 = "Ethernet0"
$NewInterfaceName1 = "Service"
Rename-NetAdapter -Name ${InterfaceName1} -NewName ${NewInterfaceName1} -PassThru
#ネットワークアダプタ2の名称変更
$InterfaceName2 = "Ethernet1"
$NewInterfaceName2 = "Management"
Rename-NetAdapter -Name ${InterfaceName2} -NewName ${NewInterfaceName2} -PassThru

出力結果

PS C:\Users\Administrator> $InterfaceName1 = "Ethernet0"
PS C:\Users\Administrator> $NewInterfaceName1 = "Service"
PS C:\Users\Administrator> Rename-NetAdapter -Name ${InterfaceName1} -NewName ${NewInterfaceName1} -PassThru

Name                      InterfaceDescription                    ifIndex Status       MacAddress             LinkSpeed
----                      --------------------                    ------- ------       ----------             ---------
Service                   Intel(R) 82574L Gigabit Network Co...#2       7 Up           00-0C-29-3C-2B-EF         1 Gbps


PS C:\Users\Administrator> $InterfaceName2 = "Ethernet1"
PS C:\Users\Administrator> $NewInterfaceName2 = "Management"
PS C:\Users\Administrator> Rename-NetAdapter -Name ${InterfaceName2} -NewName ${NewInterfaceName2} -PassThru

Name                      InterfaceDescription                    ifIndex Status       MacAddress             LinkSpeed
----                      --------------------                    ------- ------       ----------             ---------
Management                Intel(R) 82574L Gigabit Network Conn...       5 Up           00-0C-29-3C-2B-F9         1 Gbps


PS C:\Users\Administrator>

6.設定後の再起動

Restart-Computer

7.上述のIPアドレス設定を行った後の状態の確認

Get-NetIPConfiguration

出力結果

PS C:\Users\Administrator> Get-NetIPConfiguration


InterfaceAlias       : Management
InterfaceIndex       : 5
InterfaceDescription : Intel(R) 82574L Gigabit Network Connection
NetProfile.Name      : 識別されていないネットワーク
IPv4Address          : 192.168.20.202
IPv4DefaultGateway   :
DNSServer            :

InterfaceAlias       : Service
InterfaceIndex       : 7
InterfaceDescription : Intel(R) 82574L Gigabit Network Connection #2
NetProfile.Name      : ネットワーク
IPv4Address          : 192.168.10.202
IPv4DefaultGateway   : 192.168.10.1
DNSServer            : 192.168.10.1



PS C:\Users\Administrator>

4.リモートデスクトップの有効化

1.リモートデスクトップを有効化するPowerShellコマンド

Get-CimInstance -Namespace root/CIMV2/TerminalServices -ClassName Win32_TerminalServiceSetting | Invoke-CimMethod -MethodName SetAllowTSConnections -Arguments @{AllowTSConnections=1;ModifyFirewallException=1};

出力結果

PS C:\Users\Administrator> Get-CimInstance -Namespace root/CIMV2/TerminalServices -ClassName Win32_TerminalServiceSetting | Invoke-CimMethod -MethodName SetAllowTSConnections -Arguments @{AllowTSConnections=1;ModifyFirewallException=1};

ReturnValue PSComputerName
----------- --------------
          0


PS C:\Users\Administrator>

5.ディスクの設定

1.CD/DVDドライブのドライブレターをZに変更するPowerShellコマンド

#変更後のドライブレターを設定
$after_letter = "Z"
#CD/DVDドライブの現在のドライブレターを取得
$before_letter = (Get-Volume | ?{$_.DriveType -match 'CD-ROM'}).driveletter
#CD/DVDドライブのドライブ番号を取得
Write-Output "list volume" | DiskPart | ?{$_ -match ("Volume[ ]{1}(?<volume>\d)[ ]*"+ $before_letter)}
$volume = $Matches["volume"]
#CD/DVDドライブのドライブレターを変更
Write-Output ("select volume {0}`nassign letter={1}" -f $volume, $after_letter) | DiskPart

出力結果

PS C:\Users\Administrator> $after_letter = "Z"
PS C:\Users\Administrator> $before_letter = (Get-Volume | ?{$_.DriveType -match 'CD-ROM'}).driveletter
PS C:\Users\Administrator> Write-Output "list volume" | DiskPart | ?{$_ -match ("Volume[ ]{1}(?<volume>\d)[ ]*"+ $before_letter)}
  Volume 0     D                       DVD-ROM         0 B  メディアなし
PS C:\Users\Administrator> $volume = $Matches["volume"]
PS C:\Users\Administrator> Write-Output ("select volume {0}`nassign letter={1}" -f $volume, $after_letter) | DiskPart

Microsoft DiskPart バージョン 10.0.20348.1

Copyright (C) Microsoft Corporation.
コンピューター: WIN2022AD2

DISKPART>
ボリューム 0 が選択されました。

DISKPART>
DiskPart はドライブ文字またはマウント ポイントを正常に割り当てました。

DISKPART>
PS C:\Users\Administrator> Get-Volume

DriveLetter FriendlyName FileSystemType DriveType HealthStatus OperationalStatus SizeRemaining    Size
----------- ------------ -------------- --------- ------------ ----------------- -------------    ----
Z                        Unknown        CD-ROM    Healthy      Unknown                     0 B     0 B
                         NTFS           Fixed     Healthy      OK                    117.49 MB  599 MB
C                        NTFS           Fixed     Healthy      OK                     47.99 GB 59.3 GB
                         FAT32          Fixed     Healthy      OK                     67.28 MB   96 MB


PS C:\Users\Administrator>

2.Cドライブのドライブレターを設定するPowerShellコマンド

$New_C_Label = "System"
Get-Volume -DriveLetter C | Set-Volume -NewFileSystemLabel ${New_C_Label}

出力結果

PS C:\Users\Administrator> $New_C_Label = "System"
PS C:\Users\Administrator> Get-Volume -DriveLetter C | Set-Volume -NewFileSystemLabel ${New_C_Label}
PS C:\Users\Administrator> Get-Volume

DriveLetter FriendlyName FileSystemType DriveType HealthStatus OperationalStatus SizeRemaining    Size
----------- ------------ -------------- --------- ------------ ----------------- -------------    ----
Z                        Unknown        CD-ROM    Healthy      Unknown                     0 B     0 B
                         NTFS           Fixed     Healthy      OK                    117.49 MB  599 MB
C           System       NTFS           Fixed     Healthy      OK                     47.97 GB 59.3 GB
                         FAT32          Fixed     Healthy      OK                     67.28 MB   96 MB


PS C:\Users\Administrator>

3.未フォーマットのディスクに対して、オンライン、初期化、パーティション作成、フォーマット、ドライブレターを設定するPowerShellコマンド

#ディスクNo.の確認
Get-Disk
#ディスクのオンライン、初期化、パーティション作成、フォーマット、ドライブレター設定
$DiskVolume = @((1, "D", "VirtualMemory"), (2, "E", "Program"),(3, "F", "Data"))
for ($i=0; $i -lt ${DiskVolume}.count; $i++) {
    Initialize-Disk -Number ${DiskVolume}[$i][0] -PartitionStyle GPT -PassThru | New-Partition  -UseMaximumSize -DriveLetter ${DiskVolume}[$i][1] | Format-Volume -FileSystem NTFS -NewFileSystemLabel ${DiskVolume}[$i][2] -Force
}

#もし、OS再インストール等で初期化済ディスクを再利用する場合は、初期化できないので、それ以降を実施してください。
$DiskVolume = @((1, "D", "VirtualMemory"), (2, "E", "Program"),(3, "F", "Data"))
for ($i=0; $i -lt ${DiskVolume}.count; $i++) {
    New-Partition -DiskNumber ${DiskVolume}[$i][0] -UseMaximumSize -DriveLetter ${DiskVolume}[$i][1] | Format-Volume -FileSystem NTFS -NewFileSystemLabel ${DiskVolume}[$i][2] -Force
}

出力結果

PS C:\Users\Administrator> Get-Disk

Number Friendly Name                                     Serial Number                    HealthStatus         OperationalStatus      Total Size Partition                                                                                                                                                   Style      ------ -------------                                     -------------                    ------------         -----------------      ---------- ---------- 0      VMware Virtual NVMe Disk                          VMWare NVME_0000                 Healthy              Online                      60 GB GPT        1      VMware Virtual NVMe Disk                          VMWare NVME_0000                 Healthy              Online                      10 GB RAW        2      VMware Virtual NVMe Disk                          VMWare NVME_0000                 Healthy              Online                      10 GB RAW        3      VMware Virtual NVMe Disk                          VMWare NVME_0000                 Healthy              Online                      10 GB RAW                                                                                                                                                                                                                                                                                                                                PS C:\Users\Administrator> $DiskVolume = @((1, "D", "VirtualMemory"), (2, "E", "Program"),(3, "F", "Data"))
PS C:\Users\Administrator> for ($i=0; $i -lt ${DiskVolume}.count; $i++) {
>>     Initialize-Disk -Number ${DiskVolume}[$i][0] -PartitionStyle GPT -PassThru | New-Partition  -UseMaximumSize -DriveLetter ${DiskVolume}[$i][1] | Format-Volume -FileSystem NTFS -NewFileSystemLabel ${DiskVolume}[$i][2] -Force
>> }

DriveLetter FriendlyName  FileSystemType DriveType HealthStatus OperationalStatus SizeRemaining    Size
----------- ------------  -------------- --------- ------------ ----------------- -------------    ----
D           VirtualMemory NTFS           Fixed     Healthy      OK                      9.95 GB 9.98 GB
E           Program       NTFS           Fixed     Healthy      OK                      9.95 GB 9.98 GB
F           Data          NTFS           Fixed     Healthy      OK                      9.95 GB 9.98 GB


PS C:\Users\Administrator> Get-Disk

Number Friendly Name                                     Serial Number                    HealthStatus         OperationalStatus      Total Size Partition
                                                                                                                                                 Style
------ -------------                                     -------------                    ------------         -----------------      ---------- ----------
0      VMware Virtual NVMe Disk                          VMWare NVME_0000                 Healthy              Online                      60 GB GPT
1      VMware Virtual NVMe Disk                          VMWare NVME_0000                 Healthy              Online                      10 GB GPT
2      VMware Virtual NVMe Disk                          VMWare NVME_0000                 Healthy              Online                      10 GB GPT
3      VMware Virtual NVMe Disk                          VMWare NVME_0000                 Healthy              Online                      10 GB GPT


PS C:\Users\Administrator>

6.仮想メモリ・メモリダンプ設定

1.仮想メモリの設定を行うコマンド

#システムページファイルの自動管理を無効にする
$sys = Get-WmiObject -Class Win32_Computersystem –EnableAllPrivileges
$sys.AutomaticManagedPagefile = $False
$sys.Put()
#システムページファイルの変更前の状態の確認
Get-WmiObject -Class Win32_PageFileSetting | Select-Object *
#Cドライブ上のページファイルを削除
$Settings = Get-WmiObject -Class Win32_PageFileSetting | Where-Object { $_.Name -eq 'C:\pagefile.sys' }
$Settings.Delete()
#Dドライブ上にページファイルを作成
Set-WmiInstance -Class "Win32_PageFileSetting" -Arguments @{Name = "D:\pagefile.sys"; InitialSize = 4608; MaximumSize = 4608}
#システムページファイルの変更後の状態の確認
Get-WmiObject -Class Win32_PageFileSetting | Select-Object *

設定が反映されるのは再起動後です。

出力結果

PS C:\Users\Administrator> $sys = Get-WmiObject -Class Win32_Computersystem –EnableAllPrivileges
PS C:\Users\Administrator> $sys.AutomaticManagedPagefile = $False
PS C:\Users\Administrator> $sys.Put()


Path          : \\localhost\root\cimv2:Win32_ComputerSystem.Name="WIN2022AD2"
RelativePath  : Win32_ComputerSystem.Name="WIN2022AD2"
Server        : localhost
NamespacePath : root\cimv2
ClassName     : Win32_ComputerSystem
IsClass       : False
IsInstance    : True
IsSingleton   : False



PS C:\Users\Administrator> Get-WmiObject -Class Win32_PageFileSetting | Select-Object *


PSComputerName   : WIN2022AD2
__GENUS          : 2
__CLASS          : Win32_PageFileSetting
__SUPERCLASS     : CIM_Setting
__DYNASTY        : CIM_Setting
__RELPATH        : Win32_PageFileSetting.Name="C:\\pagefile.sys"
__PROPERTY_COUNT : 6
__DERIVATION     : {CIM_Setting}
__SERVER         : WIN2022AD2
__NAMESPACE      : root\cimv2
__PATH           : \\WIN2022AD2\root\cimv2:Win32_PageFileSetting.Name="C:\\pagefile.sys"
Caption          : C:\ 'pagefile.sys'
Description      : 'pagefile.sys' @ C:\
InitialSize      : 0
MaximumSize      : 0
Name             : C:\pagefile.sys
SettingID        : pagefile.sys @ C:
Scope            : System.Management.ManagementScope
Path             : \\WIN2022AD2\root\cimv2:Win32_PageFileSetting.Name="C:\\pagefile.sys"
Options          : System.Management.ObjectGetOptions
ClassPath        : \\WIN2022AD2\root\cimv2:Win32_PageFileSetting
Properties       : {Caption, Description, InitialSize, MaximumSize...}
SystemProperties : {__GENUS, __CLASS, __SUPERCLASS, __DYNASTY...}
Qualifiers       : {dynamic, Locale, provider, UUID}
Site             :
Container        :



PS C:\Users\Administrator> $Settings = Get-WmiObject -Class Win32_PageFileSetting | Where-Object { $_.Name -eq 'C:\pagefile.sys' }
PS C:\Users\Administrator> $Settings.Delete()
PS C:\Users\Administrator> Set-WmiInstance -Class "Win32_PageFileSetting" -Arguments @{Name = "D:\pagefile.sys"; InitialSize = 4608; MaximumSize = 4608}


__GENUS          : 2
__CLASS          : Win32_PageFileSetting
__SUPERCLASS     : CIM_Setting
__DYNASTY        : CIM_Setting
__RELPATH        : Win32_PageFileSetting.Name="D:\\pagefile.sys"
__PROPERTY_COUNT : 6
__DERIVATION     : {CIM_Setting}
__SERVER         : WIN2022AD2
__NAMESPACE      : root\cimv2
__PATH           : \\WIN2022AD2\root\cimv2:Win32_PageFileSetting.Name="D:\\pagefile.sys"
Caption          : D:\ 'pagefile.sys'
Description      : 'pagefile.sys' @ D:\
InitialSize      : 4608
MaximumSize      : 4608
Name             : D:\pagefile.sys
SettingID        : pagefile.sys @ D:
PSComputerName   : WIN2022AD2



PS C:\Users\Administrator> Get-WmiObject -Class Win32_PageFileSetting | Select-Object *


PSComputerName   : WIN2022AD2
__GENUS          : 2
__CLASS          : Win32_PageFileSetting
__SUPERCLASS     : CIM_Setting
__DYNASTY        : CIM_Setting
__RELPATH        : Win32_PageFileSetting.Name="D:\\pagefile.sys"
__PROPERTY_COUNT : 6
__DERIVATION     : {CIM_Setting}
__SERVER         : WIN2022AD2
__NAMESPACE      : root\cimv2
__PATH           : \\WIN2022AD2\root\cimv2:Win32_PageFileSetting.Name="D:\\pagefile.sys"
Caption          : D:\ 'pagefile.sys'
Description      : 'pagefile.sys' @ D:\
InitialSize      : 4608
MaximumSize      : 4608
Name             : D:\pagefile.sys
SettingID        : pagefile.sys @ D:
Scope            : System.Management.ManagementScope
Path             : \\WIN2022AD2\root\cimv2:Win32_PageFileSetting.Name="D:\\pagefile.sys"
Options          : System.Management.ObjectGetOptions
ClassPath        : \\WIN2022AD2\root\cimv2:Win32_PageFileSetting
Properties       : {Caption, Description, InitialSize, MaximumSize...}
SystemProperties : {__GENUS, __CLASS, __SUPERCLASS, __DYNASTY...}
Qualifiers       : {dynamic, Locale, provider, UUID}
Site             :
Container        :



PS C:\Users\Administrator>

2.メモリダンプの設定を行うコマンド

#システムの起動と回復設定の確認
$CrashBehaviour = Get-WmiObject -Class Win32_OSRecoveryConfiguration -EnableAllPrivileges
$CrashBehaviour | Format-List *
#ダンプファイルの配置場所の変更
$CrashBehaviour | Set-WmiInstance -Arguments @{ DebugFilePath='D:\MEMORY.DMP' }

設定が反映されるのは再起動後です。

出力結果

PS C:\Users\Administrator> $CrashBehaviour = Get-WmiObject -Class Win32_OSRecoveryConfiguration -EnableAllPrivileges
PS C:\Users\Administrator> $CrashBehaviour | Format-List *


PSComputerName             : WIN2022AD2
__GENUS                    : 2
__CLASS                    : Win32_OSRecoveryConfiguration
__SUPERCLASS               : CIM_Setting
__DYNASTY                  : CIM_Setting
__RELPATH                  : Win32_OSRecoveryConfiguration.Name="Microsoft Windows Server 2022 Standard Evaluation|C:\\Windows|\\Device\\Harddisk0\\Partiti
                             on3"
__PROPERTY_COUNT           : 15
__DERIVATION               : {CIM_Setting}
__SERVER                   : WIN2022AD2
__NAMESPACE                : root\cimv2
__PATH                     : \\WIN2022AD2\root\cimv2:Win32_OSRecoveryConfiguration.Name="Microsoft Windows Server 2022 Standard Evaluation|C:\\Windows|\\Devi
                             ce\\Harddisk0\\Partition3"
AutoReboot                 : True
Caption                    :
DebugFilePath              : %SystemRoot%\MEMORY.DMP
DebugInfoType              : 7
Description                :
ExpandedDebugFilePath      : C:\Windows\MEMORY.DMP
ExpandedMiniDumpDirectory  : C:\Windows\Minidump
KernelDumpOnly             : False
MiniDumpDirectory          : %SystemRoot%\Minidump
Name                       : Microsoft Windows Server 2022 Standard Evaluation|C:\Windows|\Device\Harddisk0\Partition3
OverwriteExistingDebugFile : True
SendAdminAlert             : False
SettingID                  :
WriteDebugInfo             : True
WriteToSystemLog           : True
Scope                      : System.Management.ManagementScope
Path                       : \\WIN2022AD2\root\cimv2:Win32_OSRecoveryConfiguration.Name="Microsoft Windows Server 2022 Standard Evaluation|C:\\Windows|\\Devi
                             ce\\Harddisk0\\Partition3"
Options                    : System.Management.ObjectGetOptions
ClassPath                  : \\WIN2022AD2\root\cimv2:Win32_OSRecoveryConfiguration
Properties                 : {AutoReboot, Caption, DebugFilePath, DebugInfoType...}
SystemProperties           : {__GENUS, __CLASS, __SUPERCLASS, __DYNASTY...}
Qualifiers                 : {dynamic, Locale, provider, UUID}
Site                       :
Container                  :



PS C:\Users\Administrator> $CrashBehaviour | Set-WmiInstance -Arguments @{ DebugFilePath='D:\MEMORY.DMP' }

DebugFilePath Name                                                                                      SettingID
------------- ----                                                                                      ---------
D:\MEMORY.DMP Microsoft Windows Server 2022 Standard Evaluation|C:\Windows|\Device\Harddisk0\Partition3


PS C:\Users\Administrator> $CrashBehaviour = Get-WmiObject -Class Win32_OSRecoveryConfiguration -EnableAllPrivileges
PS C:\Users\Administrator> $CrashBehaviour | Format-List *


PSComputerName             : WIN2022AD2
__GENUS                    : 2
__CLASS                    : Win32_OSRecoveryConfiguration
__SUPERCLASS               : CIM_Setting
__DYNASTY                  : CIM_Setting
__RELPATH                  : Win32_OSRecoveryConfiguration.Name="Microsoft Windows Server 2022 Standard Evaluation|C:\\Windows|\\Device\\Harddisk0\\Partiti
                             on3"
__PROPERTY_COUNT           : 15
__DERIVATION               : {CIM_Setting}
__SERVER                   : WIN2022AD2
__NAMESPACE                : root\cimv2
__PATH                     : \\WIN2022AD2\root\cimv2:Win32_OSRecoveryConfiguration.Name="Microsoft Windows Server 2022 Standard Evaluation|C:\\Windows|\\Devi
                             ce\\Harddisk0\\Partition3"
AutoReboot                 : True
Caption                    :
DebugFilePath              : D:\MEMORY.DMP
DebugInfoType              : 7
Description                :
ExpandedDebugFilePath      : D:\MEMORY.DMP
ExpandedMiniDumpDirectory  : C:\Windows\Minidump
KernelDumpOnly             : False
MiniDumpDirectory          : %SystemRoot%\Minidump
Name                       : Microsoft Windows Server 2022 Standard Evaluation|C:\Windows|\Device\Harddisk0\Partition3
OverwriteExistingDebugFile : True
SendAdminAlert             : False
SettingID                  :
WriteDebugInfo             : True
WriteToSystemLog           : True
Scope                      : System.Management.ManagementScope
Path                       : \\WIN2022AD2\root\cimv2:Win32_OSRecoveryConfiguration.Name="Microsoft Windows Server 2022 Standard Evaluation|C:\\Windows|\\Devi
                             ce\\Harddisk0\\Partition3"
Options                    : System.Management.ObjectGetOptions
ClassPath                  : \\WIN2022AD2\root\cimv2:Win32_OSRecoveryConfiguration
Properties                 : {AutoReboot, Caption, DebugFilePath, DebugInfoType...}
SystemProperties           : {__GENUS, __CLASS, __SUPERCLASS, __DYNASTY...}
Qualifiers                 : {dynamic, Locale, provider, UUID}
Site                       :
Container                  :



PS C:\Users\Administrator>

3.設定後の再起動

Restart-Computer

メモリダンプの設定確認(テスト)を行う方法はこちらの記事に記載しています。

7.Windows updateの実施(PSWindowsUpdateモジュールを使用)

PSWindowsUpdateモジュールでインストールできるものとできないものがあるようで調査中です。

1.「PSWindowsUpdate」モジュールのインストールを行うコマンド

Install-Module PSWindowsUpdate

出力結果

PS C:\Users\Administrator> Install-Module PSWindowsUpdate

続行するには NuGet プロバイダーが必要です                                                                                                                   PowerShellGet で NuGet ベースのリポジトリを操作するには、'2.8.5.201' 以降のバージョンの NuGet プロバイダーが必要です。NuGet プロバイダーは 'C:\Program      Files\PackageManagement\ProviderAssemblies' または 'C:\Users\Administrator\AppData\Local\PackageManagement\ProviderAssemblies'                              に配置する必要があります。'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force' を実行して NuGet                                           プロバイダーをインストールすることもできます。今すぐ PowerShellGet で NuGet プロバイダーをインストールしてインポートしますか?                               [Y] はい(Y)  [N] いいえ(N)  [S] 中断(S)  [?] ヘルプ (既定値は "Y"): Y

信頼されていないリポジトリ
信頼されていないリポジトリからモジュールをインストールしようとしています。このリポジトリを信頼する場合は、Set-PSRepository
コマンドレットを実行して、リポジトリの InstallationPolicy の値を変更してください。'PSGallery' からモジュールをインストールしますか?
[Y] はい(Y)  [A] すべて続行(A)  [N] いいえ(N)  [L] すべて無視(L)  [S] 中断(S)  [?] ヘルプ (既定値は "N"): Y
PS C:\Users\Administrator>

2.他のMicrosoft製品の更新も行う場合のコマンド

Add-WUServiceManager -MicrosoftUpdate

出力結果

PS C:\Users\Administrator> Add-WUServiceManager -MicrosoftUpdate

確認
この操作を実行しますか?
対象 "WIN2022AD2" に対して操作 "(2022/05/02 23:53:24) Register Windows Update Service Manager: 7971f918-a847-4430-9279-4a52d1efe18d" を実行しています。
[Y] はい(Y)  [A] すべて続行(A)  [N] いいえ(N)  [L] すべて無視(L)  [S] 中断(S)  [?] ヘルプ (既定値は "Y"): Y

ServiceID                            IsManaged IsDefault Name
---------                            --------- --------- ----
7971f918-a847-4430-9279-4a52d1efe18d False     False     Microsoft Update


PS C:\Users\Administrator>

3.WindowsUpdateによる更新プログラムの確認を行うコマンド

#通常の場合の確認
Get-WindowsUpdate
#特定の更新プログラムを指定して取得
Get-WindowsUpdate -KBArticleID 'KBxxxxxxx', 'KBxxxxxxx' -Install

出力結果

PS C:\Users\Administrator> Get-WindowsUpdate

ComputerName Status     KB          Size Title
------------ ------     --          ---- -----
WIN2022AD2   -D-----    KB890830    42MB 悪意のあるソフトウェアの削除ツール x64 - v5.98 (KB890830)
WIN2022AD2   -------    KB5010475   47MB .NET Framework 3.5 用の2022-02累積的な更新プログラムのプレビューと x64 (KB5010475) のMicrosoft server operating...
WIN2022AD2   -D-----    KB890830    39MB 悪意のあるソフトウェアの削除ツール x64 - v5.100 (KB890830)
WIN2022AD2   -------    KB5012160   47MB .NET Framework 3.5 用の2022-04累積的な更新プログラムのプレビューと x64 (KB5012160) のMicrosoft server operating...
WIN2022AD2   -D-----    KB2267602  986MB Microsoft Defender Antivirus のセキュリティ インテリジェンス更新プログラム - KB2267602 (バージョン 1.363.1295.0)
WIN2022AD2   -D-----    KB5012604   24GB 2022-04 Microsoft server operating system version 21H2 x64 ベース システム用の累積更新プログラム (KB5012604)


PS C:\Users\Administrator>

4.更新プログラムのインストールを行うコマンド

#通常の更新プログラムのインストール
Install-WindowsUpdate
#すべての更新プログラムをインストールした後でコンピューターを自動的に再起動する場合
Install-WindowsUpdate -MicrosoftUpdate -AcceptAll -AutoReboot
#特定の更新プログラムがコンピューターにインストールされないようにする場合
Install-WindowsUpdate -NotKBArticle 'KBxxxxxxx, KBxxxxxxx' -AcceptAll

出力結果

PS C:\Users\Administrator> Install-WindowsUpdate

確認                                                                                                                                                        この操作を実行しますか?                                                                                                                                     対象 "WIN2022AD2" に対して操作 "(2022/05/02 23:58:48) 悪意のあるソフトウェアの削除ツール x64 - v5.98 (KB890830)[42MB]" を実行しています。                     [Y] はい(Y)  [A] すべて続行(A)  [N] いいえ(N)  [L] すべて無視(L)  [S] 中断(S)  [?] ヘルプ (既定値は "Y"): A                                                                                                                                                                                                             X ComputerName Result     KB          Size Title
- ------------ ------     --          ---- -----
1 WIN2022AD2   Accepted   KB890830    42MB 悪意のあるソフトウェアの削除ツール x64 - v5.98 (KB890830)
1 WIN2022AD2   Accepted   KB5010475   47MB .NET Framework 3.5 用の2022-02累積的な更新プログラムのプレビューと x64 (KB5010475) のMicrosoft server operati...
1 WIN2022AD2   Accepted   KB890830    39MB 悪意のあるソフトウェアの削除ツール x64 - v5.100 (KB890830)
1 WIN2022AD2   Accepted   KB5012160   47MB .NET Framework 3.5 用の2022-04累積的な更新プログラムのプレビューと x64 (KB5012160) のMicrosoft server operati...
1 WIN2022AD2   Accepted   KB2267602  986MB Microsoft Defender Antivirus のセキュリティ インテリジェンス更新プログラム - KB2267602 (バージョン 1.363.1295.0)
1 WIN2022AD2   Accepted   KB5012604   24GB 2022-04 Microsoft server operating system version 21H2 x64 ベース システム用の累積更新プログラム (KB5012604)
2 WIN2022AD2   Downloaded KB890830    42MB 悪意のあるソフトウェアの削除ツール x64 - v5.98 (KB890830)
2 WIN2022AD2   Downloaded KB5010475   47MB .NET Framework 3.5 用の2022-02累積的な更新プログラムのプレビューと x64 (KB5010475) のMicrosoft server operati...
2 WIN2022AD2   Downloaded KB890830    39MB 悪意のあるソフトウェアの削除ツール x64 - v5.100 (KB890830)
2 WIN2022AD2   Downloaded KB5012160   47MB .NET Framework 3.5 用の2022-04累積的な更新プログラムのプレビューと x64 (KB5012160) のMicrosoft server operati...
2 WIN2022AD2   Downloaded KB2267602  986MB Microsoft Defender Antivirus のセキュリティ インテリジェンス更新プログラム - KB2267602 (バージョン 1.363.1295.0)
2 WIN2022AD2   Downloaded KB5012604   24GB 2022-04 Microsoft server operating system version 21H2 x64 ベース システム用の累積更新プログラム (KB5012604)
3 WIN2022AD2   Installed  KB890830    42MB 悪意のあるソフトウェアの削除ツール x64 - v5.98 (KB890830)
3 WIN2022AD2   Installed  KB5010475   47MB .NET Framework 3.5 用の2022-02累積的な更新プログラムのプレビューと x64 (KB5010475) のMicrosoft server operati...
3 WIN2022AD2   Installed  KB890830    39MB 悪意のあるソフトウェアの削除ツール x64 - v5.100 (KB890830)
3 WIN2022AD2   Installed  KB5012160   47MB .NET Framework 3.5 用の2022-04累積的な更新プログラムのプレビューと x64 (KB5012160) のMicrosoft server operati...
3 WIN2022AD2   Failed     KB2267602  986MB Microsoft Defender Antivirus のセキュリティ インテリジェンス更新プログラム - KB2267602 (バージョン 1.363.1295.0)
3 WIN2022AD2   Installed  KB5012604   24GB 2022-04 Microsoft server operating system version 21H2 x64 ベース システム用の累積更新プログラム (KB5012604)
Reboot is required. Do it now? [Y / N] (default is 'N')

以上

コメント