it技術:powershell
文書の過去の版を表示しています。
PowerShell
Tips
値を編集して出力
PS > Get-WMIObject Win32_ServerFeature | Select {$_.Name + ":"} $_.Name + ":" ------------- ファイル サービスと記憶域サービス: SMB 1.0/CIFS ファイル共有のサポート:
列名を変更する。
PS > Get-WMIObject Win32_ServerFeature | Select @{name="name";expression={$_.Name + ":"}} name ---- ファイル サービスと記憶域サービス: SMB 1.0/CIFS ファイル共有のサポート:
IISのDefault Web Siteの値取得
Default Web Siteの値を取得する
PS > Get-ItemProperty 'IIS:\Sites\Default Web Site\' | Select * name : Default Web Site id : 1 serverAutoStart : True state : Started bindings : Microsoft.IIs.PowerShell.Framework.ConfigurationElement limits : Microsoft.IIs.PowerShell.Framework.ConfigurationElement logFile : Microsoft.IIs.PowerShell.Framework.ConfigurationElement traceFailedRequestsLogging : Microsoft.IIs.PowerShell.Framework.ConfigurationElement applicationDefaults : Microsoft.IIs.PowerShell.Framework.ConfigurationElement virtualDirectoryDefaults : Microsoft.IIs.PowerShell.Framework.ConfigurationElement ftpServer : Microsoft.IIs.PowerShell.Framework.ConfigurationElement Collection : {Microsoft.IIs.PowerShell.Framework.ConfigurationElement, Microsoft.IIs.PowerShell.Framework.ConfigurationElement, Microsoft.IIs.PowerShell.Framewor k.ConfigurationElement, Microsoft.IIs.PowerShell.Framework.ConfigurationElement...} applicationPool : DefaultAppPool enabledProtocols : http physicalPath : %SystemDrive%\inetpub\wwwroot userName : password : ItemXPath : /system.applicationHost/sites/site[@name='Default Web Site' and @id='1'] PSPath : WebAdministration::\\GOUNN2\Sites\Default Web Site\ PSParentPath : WebAdministration::\\GOUNN2\Sites PSChildName : Default Web Site\ PSDrive : IIS PSProvider : WebAdministration PSIsContainer : True Attributes : {name, id, serverAutoStart, state} ChildElements : {bindings, limits, logFile, traceFailedRequestsLogging...} ElementTagName : site Methods : {Start, Stop} Schema : Microsoft.IIs.PowerShell.Framework.ConfigurationElementSchema
ASPプロパティ内のセッションプロパティの値を取得する。
PS > Get-WebConfiguration system.webServer/asp/session -Location 'Default Web Site' PS > Get-WebConfiguration -PSPath 'MACHINE/WEBROOT/APPHOST/Default Web Site' system.webServer/asp/session PS > Get-WebConfigurationProperty -Location 'Default Web Site' -Filter "system.webServer/asp/session" -Name "." PS > Get-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST/Default Web Site' -Filter "system.webServer/asp/session" -Name "."
二重引用符はエスケープ
VBScriptからPowerShellを呼び出す際に二重引用符が使用されている場合には、「\“」でエスケープする必要がある。
name = "DefaultAppPool2" command = "Get-WebConfiguration \""//*[@name='" & name & "']//.\""" info = "foreach { $_.attributes | Select name, value }" Sub SetDicItems(dic, command, info, delimiter) Dim exeCommand exeCommand = "powershell -nologo -command " & command & " | " & info Call SetDicStdOut(dic, exeCommand, delimiter) End Sub ------------------------------------------------------------------------ ' 標準出力からの出力項目をセット '------------------------------------------------------------------------ Sub SetDicStdOut(dic, exeCommand, delimiter) Dim exec, line, key, pos dic.RemoveAll() Set exec = wsh.Exec(exeCommand) exec.StdIn.Close() Do line = exec.StdOut.ReadLine() If Trim(line) <> "" Then pos = Instr(line, delimiter) If pos > 0 Then key = Trim(Mid(line, 1, pos-1)) If Not dic.Exists(key) Then dic.Add key, Trim(Mid(line, pos+1)) End If End If End If Loop While Not exec.Stdout.atEndOfStream Set exec = Nothing End Sub
it技術/powershell.1563941266.txt.gz · 最終更新: 2019/07/24 13:07 by yajuadmin