Блокнот сисадмина PowerShell
Здесь можно узнать как командами можно получить сведения об операционной системе Windows.
Get-Command -Noun *WMI*
Get-WmiObject -List | where {$_.Name -Like "*share*"}
Get-WmiObject -Class Win32_Share
Get-WmiObject -Class Win32_Share -Filter "Status = 'OK'"
вывести объекты классов:
Get-WmiObject -List | sort name | format-table Name, Methods, Properties
Get-WmiObject -List | sort name | format-table Name, Properties
вывести параметры классов:
Get-WmiObject -Class "Win32_OperatingSystem" | format-list Properties
Get-WmiObject -Class "Win32_ComputerSystem" | Format-List *
Get-WmiObject -Class "Win32_OperatingSystem" | Format-List *
Get-WmiObject -Class "Win32_SystemAccount" | Format-List *
Get-WmiObject -Class "win32_account" | Format-List *
Get-WmiObject -Class "Win32_Service" | Format-List *
Списки пользователей и групп:
Get-WmiObject -Class Win32_SystemAccount
Get-Wmiobject -class "win32_account" -namespace "root\cimv2" | sort Caption | format-table Caption, __CLASS, FullName
#сортировка по Caption#
Get-WmiObject -Class "Win32_SystemAccount" -namespace "root\cimv2" | sort Caption | format-table Caption, Domain, Name, SID
Get-WmiObject -Class "Win32_Group" -namespace "root\cimv2" | sort caption | format-table Caption, Domain, Name, SID
Get-WmiObject -Class "Win32_UserAccount" -namespace "root\cimv2" | sort caption | format-table Caption, Domain, Name, SID
#сортировка по Sid#
Get-WmiObject -Class "Win32_SystemAccount" -namespace "root\cimv2" | sort Sid | format-table Caption, Domain, Name, SID
Get-WmiObject -Class "Win32_Group" -namespace "root\cimv2" | sort Sid | format-table Caption, Domain, Name, SID
Get-WmiObject -Class "Win32_UserAccount" -namespace "root\cimv2" | sort Sid | format-table Caption, Domain, Name, SID
Get-WmiObject -Class "Win32_Service" -namespace "root\cimv2" | sort Sid | format-table Caption, Domain, Name, SID
Get-WmiObject -Class "Win32_SystemServices" -namespace "root\cimv2" | sort Sid | format-table Caption, Domain, Name, SID
Get-WmiObject -Class "Win32_Service" -namespace "root\cimv2" | sort Sid | format-table Caption, Domain, Name, SID
Список всех пользователей и их SID:
gwmi -class win32_account -namespace "root\cimv2" | sort Sid | format-table Caption, SID, Path
(писать Domain, Name не нужно, это есть в Caption)
gwmi -class win32_account -namespace "root\cimv2" | Out-GridView -PassThru
Get-WmiObject -Class "Win32_SystemAccount" | Format-List *
Список служб:
gwmi -Class "Win32_Service" -namespace "root\cimv2" | sort Caption | format-table Caption, Path, Name, ProcessId
gwmi -Class "Win32_Service" -namespace "root\cimv2" | sort Caption | format-table Caption, pathName
gwmi -Class "Win32_Service" -namespace "root\cimv2" | sort Caption | format-table Caption, startName
gwmi -Class "Win32_Service" -namespace "root\cimv2" | sort Caption | format-table Caption, Name, STATUS, State, StartMode
gwmi -Class "Win32_Service" -namespace "root\cimv2" | Out-GridView -PassThru
Get-WmiObject -Class "Win32_UserProfile" -namespace "root\cimv2"
Get-WmiObject -Class "Win32_UserProfile" -namespace "root\cimv2" | sort Sid | format-table LocalPath, SID
Get-WmiObject -Class "Win32_UserProfile" -namespace "root\cimv2" | Out-GridView -PassThru
gwmi -Class Win32_GroupUser -namespace "root\cimv2"
gwmi -class win32_account -Filter 'name="LOCAL SERVICE"' | % {return $_.startname}
gwmi -class win32_account -Filter 'name="LOCAL SERVICE"'
gwmi -class win32_account -Filter 'name="NETWORK SERVICE"'
gwmi Win32_service -Filter "name='dhcp'" | % {return $_.startname}
TrustedInstaller из powershell
([system.security.Principal.ntaccount]'NT SERVICE\TrustedInstaller').translate([security.principal.securityidentifier])
Бат-файл SID TrustedInstaller из powershell:
@echo off
powershell.exe -noexit -command "& {([system.security.Principal.ntaccount]'NT SERVICE\TrustedInstaller').translate([security.principal.securityidentifier])}"
pause
Получение данных из ОС:
Команда вывода списка параметров таблицы:
Get-WmiObject -Class Win32_OperatingSystem -Namespace root/cimv2 -ComputerName . | Get-Member -MemberType Property
Get-WmiObject -Class Win32_OperatingSystem -Namespace root/cimv2 -ComputerName . | format-list
Get-WmiObject -Class "Win32_OperatingSystem" | Format-List *
простая команда:
Get-WmiObject -Class Win32_OperatingSystem -namespace "root\cimv2" | format-table BuildNumber, SerialNumber, Version, Caption
расширенная команда:
Get-WmiObject -Class Win32_OperatingSystem -Namespace "root\cimv2" | format-list BuildNumber, SerialNumber, Version, Caption, RegisteredUser, InstallDate, CodeSet, MUILanguages, Name, BuildType, OSArchitecture, PSComputerName
Конвертирует дату установки ОС:
get-wmiobject win32_operatingsystem | select @{Name="Installed"; Expression={$_.ConvertToDateTime($_.InstallDate)}}, Caption
дополнительно:
Get-WmiObject -Class Win32_OperatingSystem | Select-Object -Property *
Get-WmiObject -Class Win32_OperatingSystem -namespace "root\cimv2" | Out-GridView -PassThru
Get-WmiObject -Class Win32_OperatingSystem -Namespace root/cimv2 -ComputerName .
Из реестра:
Как узнать версию ОС в нужном списке с командной строки.
Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" | format-list ProductName, DisplayVersion, CurrentBuild, BuildLabEx, VersionString, OsVersion, EditionID
Бат-файл:
@echo off
powershell.exe -noexit -command "& {Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' | format-list ProductName, DisplayVersion, CurrentBuild, BuildLabEx, VersionString, OsVersion, EditionID}"
pause
Железо:
Get-WmiObject -Class Win32_OperatingSystem -Namespace root/cimv2 -ComputerName . | Format-List TotalVirtualMemorySize,TotalVisibleMemorySize,FreePhysicalMemory,FreeVirtualMemory,FreeSpaceInPagingFiles
Get-WmiObject -Class Win32_OperatingSystem -Namespace root/cimv2 -ComputerName . | Format-Table -Property TotalVirtualMemorySize,TotalVisibleMemorySize,FreePhysicalMemory,FreeVirtualMemory,FreeSpaceInPagingFiles
