我寫信使用salt和windows進行檢查。我認爲它只是語法,我對powershell很新,任何幫助都會很棒。單線程獲取服務啓動類型
powershell -NoProfile "if (Get-Service someCoolService -ErrorAction SilentlyContinue) -And if (someCoolService.StartUpType -ne "Disabled") { Write-Output "True" }
我寫信使用salt和windows進行檢查。我認爲它只是語法,我對powershell很新,任何幫助都會很棒。單線程獲取服務啓動類型
powershell -NoProfile "if (Get-Service someCoolService -ErrorAction SilentlyContinue) -And if (someCoolService.StartUpType -ne "Disabled") { Write-Output "True" }
就像你說的那樣,它的語法錯誤。如果你想自己修復它,我建議你下次打開一個PowerShell窗口,然後在「powershell -Noprofile」 - >之後執行所有內容,因爲如果你在PowerShell窗口中,這個部分是不需要的。 (要運行powershell,只需在命令提示符下鍵入powershell或從應用程序中打開PowerShell窗口)。
無論如何,讓我來幫助你解決這個問題,同時你可以使用我之前提到過的你以後卡住的問題。
powershell -profile if((Get-Service someCoolService -ErrorAction SilentlyContinue) -And (someCoolService.StartUpType -ne "Disabled")) { Write-Output "True" }
使用WMI此:
salt '*' cmd.run "![bool](Get-WmiObject Win32_Service -Filter \"Name='yourService' AND StartMode='Disabled'\"" shell='powershell'
我有鹽部分正確,我不明白語法錯誤,以及。我試圖解決它無濟於事,因爲我仍然是新的,並試圖瞭解PowerShell。感謝您向我展示有關WMI的信息。谷歌有例子,但他們werent很有幫助。 – user2462320 2015-01-27 14:44:55
謝謝:
你在談論的SaltStack配置管理系統,您也應該能夠run PowerShell code directly通過指定
shell
參數假設您。是的,我打開PS並做了所有這些,但是我不明白的錯誤,我搜索了一些例子,並且從未真正正確地工作過。不知道錯誤的含義是什麼。但是謝謝。 – user2462320 2015-01-27 14:56:27太棒了!很高興知道它幫助:) – Inchara 2015-01-27 18:45:36