見出し画像

Windows コマンドメモ(自動化のため?)

Change Network Interface name

netsh interface ipv4 show interfaces
netsh interface set interface name='旧名称' newname='新名称'

Add computer to AD

Add-Computer -ComputerName <computer name> -Credential <ad domain>\<service account name>

Download file from a web server

$WebClient = New-Object System.Net.WebClient
$WebClient.DownloadFile("https://www.contoso.com/file/xxxxxxxx","C:\path\file")

パスワードを無期限に変更

wmic UserAccount where Name='ユーザー名' set PasswordExpires=False

Set-LocalUser -Name ユーザー名 -PasswordNeverExpire $true

NetBiosを無効にする

# LMHOSTS 参照 Disable
$RegPath = "HKLM:\SYSTEM\CurrentControlSet\Services\NetBT\Parameters"
$RegKey = "EnableLMHOSTS"
$RegData = 0
 
Set-ItemProperty $RegPath -name $RegKey -Value $RegData
 
# NBT Disable
$RegPath = "HKLM:\SYSTEM\CurrentControlSet\Services\NetBT\Parameters\Interfaces"
$RegKey = "NetbiosOptions"
$RegData = 2
 
$NICs = Get-ChildItem $RegPath
foreach( $NIC in $NICs ){
    $NicReg = $RegPath + "\" + $NIC.PSChildName
    Set-ItemProperty $NicReg -name $RegKey -Value $RegData
}

Windows自動Updateを無効化、フィードバックと診断の無効化、

Windows自動Updateを無効化
reg add HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU /v NoAutoUpdate /t REG_DWORD /d 1 /f

フィードバックと診断の無効化

reg add HKLM\SOFTWARE\Policies\Microsoft\Windows\DataCollection /v AllowTelemetry /t REG_DWORD /d 0  /f
sc stop DiagTrack
sc config DiagTrack start=disabled

IPv6を無効にする

AdapterのIPv6無効化
Disable-NetAdapterBinding -Name "イーサネット" -ComponentID ms_tcpip6

Get-NetAdapterBinding -Name "イーサネット" -ComponentID ms_tcpip6

インタフェースのIPv6無効化
netsh interface ipv6 isatap set state disabled

netsh interface ipv6 6to4 set state disabled

netsh interface ipv6 set teredo disabled

Change NIC name

netsh interface show interface
netsh interface set interface name="Current Name" newname="New Name"
 
  #PowerShell 
Get-NetAdapter | format-list
Rename-NetAdapter -Name "Current Name" -NewName "New Name"

Add Domain Group/User to "Remote Desktop Users"

Add-LocalGroupMember -Name "Remote Desktop Users" -Member "xxxxxx\dev1"
Get-LocalGroupMember -Name "Remote Desktop Users"

Format and initialize a new DISK

$number = 1;
$driveLetter = "Q";
$disk = Get-Disk -Number $number | Where-Object IsSystem -eq $false;

$disk | Clear-Disk -RemoveData -RemoveOEM -confirm:$false;
$disk | Initialize-Disk -PartitionStyle MBR;
$disk | New-Partition -UseMaximumSize -DriveLetter $driveLetter;

Format-Volume -DriveLetter $driveLetter -FileSystem NTFS -Confirm:$false -Force;

Change the 3rd octet of Windows IP address

$NIC = "Ethernet 2"
$PREFIXLENGTH = 24

$oldIP = (Get-NetIPAddress -InterfaceAlias $NIC).IPAddress

# if multi-IPs assigned to the NIC, change the first IP.
if ($oldIP.count -gt 1) {
  $oldIP = $oldIP[0]
}

$octets = $oldIP.Split(".") 
$octets[2] = "210"   #the  3rd octet, replace this value
$newIP = $octets -join "."

Get-NetAdapter -InterfaceAlias $NIC | `
    Remove-NetIPAddress -IPAddress $oldIP -confirm:$false
Get-NetAdapter -InterfaceAlias $NIC | `
    New-NetIPAddress -IPAddress $newIP -PrefixLength $PREFIXLENGTH

Restart-NetAdapter -Name $NIC

この記事が気に入ったらサポートをしてみませんか?