Powershell
Not Posted
2017年記事にしそこねたやったこと
- コマンドプロンプト(バッチファイル)
- コマンドプロンプトからPowershell実行
- シェルスクリプト
- AWS System Manager Run Command (sum)
- VagrantでSQL Server他DBもセットアップしたよ
- Nano Server試そうとした
- React Redux…etc
- Webpack
- Docker再入門とWP開発環境の作成
- WordPressテーマ開発用のベースを作成した
- AWS Lambda をPythonで
- AWS Lambda をNode.jsで
- CakePHP 3 tutorial 少しやった
- Vagrant でPHP開発環境作成
- Terraform試した
- Hugo用テーマを作成した
忙しいというよりは怠惰だったのと、Hugoのテーマを変えてからやろうと言い訳してるうちに忘れてしまった。
コマンドプロンプト(バッチファイル)
Windowsサーバーでバッチファイルで操作しようとした時に少しおぼえた。
例えばこんなこと。実行結果を変数に入れるのが面倒。
setlocal enabledelayedexpansion
for /f %%a in ('whoami') do @set watashi=%%a
echo %date% %time% !watashi! >> execute.log
別プロセスで実行する方法
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