Powershell

Powershellでやったことメモn

Powershellの実行権限について

Get-ExecutionPolicy
Set-ExecutionPolicy <PolicyName> # RemoteSignedとか

よく使いそうなやつ

ファイル操作、実行、インストールなど

Copy-Item <<source>> -Destination <<dest>> -Recurse
Move-Item <<sourse>> -Destination <<dest>>
Remove-Item <<source>> -Recurse
Rename-Item <<sourse>>
Get-Content <<path/to/file>> 

Get-WmiObject Win32_Product

Enter-PSSession <<container_id>> -RunAsAdministrator

docker inspect <<container>> --format="{{.Id}}" | sv container_id

Install-WindowsFeature -Name <<FeatureName | SubFeatureName>>
Install-WindowsFeature Web-Server -IncludeAllSubFeature

Get-NetTCPConnection

Get-WebSiteState -Name <<WebSiteName>>

Start-WebSite -Name <<WebSiteName>>
Stop-WebSite -Name <<WebSiteName>>

Get-WindowsFeature -Name Web-Server
Get-WindowsFeature -Name Web-*

IIS関連

Import-Module IISAdministration 

Reset-IISServerManager -confirm:$false
$sm = Get-IISServerManager
$appHostconfig = $sm.GetApplicationHostConfiguration() 
$section = $appHostconfig.GetSection("system.webServer/handlers") 
$section.OverrideMode="Allow" 
$sm.CommitChanges()

Reset-IISServerManager -confirm:$false
$sm = Get-IISServerManager
$appHostconfig = $sm.GetApplicationHostConfiguration() 
$sectionHttpPlatform = $appHostConfig.RootSectionGroup.SectionGroups["system.webServer"].Sections.Add("httpPlatform") 
$sectionHttpPlatform.OverrideModeDefault = "Allow"
$sm.CommitChanges()

Reset-IISServerManager -confirm:$false
$globalModules = Get-IISConfigSection "system.webServer/globalModules" | Get-IISConfigCollection 
New-IISConfigCollectionElement $globalModules -ConfigAttribute @{"name"="httpPlatformHandler";"image"="%windir%\system32\inetsrv\httpPlatformHandler.dll"} 
 
Reset-IISServerManager -confirm:$false
$modules = Get-IISConfigSection "system.webServer/modules" | Get-IISConfigCollection 
New-IISConfigCollectionElement $modules -ConfigAttribute @{"name"="httpPlatformHandler"}

運用場面でよく使いそうなもの

Get-Process

Get-ChildItem env:

Get-WmiObject Win32_PerfFormattedData_PerfOS_Memory 

Get-ChildItem -Path Registry::HKEY_LOCAL_MACHINE\Software\JavaSoft...

New-Item -Path Registry::HKLM\...

Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion

New-ItemProperty -Path "HKLM:\SOFTWARE\JavaSoft\Java Runtime Environment" -Name CurrentVersion -PropertyType String -Value 1.8

コマンドラインでインストール

msiexec /i <</path/to/msi>> /qn

Setup.exe /s /qn