powershell-2.0

How to timeout PowerShell function call

二次信任 提交于 2019-12-20 19:32:33
问题 I wrote a little powershell function that executes Get-EventLog against remote servers. On some servers this seems to just hang and never times out. Can I timeout a powershell function call? I see how to do this against a different process, but i want to do this for a power shell function. thanks ####################### function Get-Alert4 { param($computer) $ret = Get-EventLog application -after (get-date).addHours(-2) -computer $computer | select-string -inputobject{$_.message} -pattern

relative path in Import-Module

坚强是说给别人听的谎言 提交于 2019-12-20 16:22:35
问题 I have directory structure that looks like this: C:\TFS\MasterScript\Script1.ps1 C:\TFS\ChildScript\Script2.ps1 What i want to do is specify the relative path in Script2.ps1 to look for Script1.ps1 in the directory hirearchy. This is what i tried in Script2.ps1: Import-Module ../MasterScript/Script1.ps1 but it does not work and says it cannot find the module. If i say Import-Module C:\TFS\MasterScript\Script1.ps1 , it works fine. What am i missing here? 回答1: When you use a relative path, it

relative path in Import-Module

▼魔方 西西 提交于 2019-12-20 16:21:51
问题 I have directory structure that looks like this: C:\TFS\MasterScript\Script1.ps1 C:\TFS\ChildScript\Script2.ps1 What i want to do is specify the relative path in Script2.ps1 to look for Script1.ps1 in the directory hirearchy. This is what i tried in Script2.ps1: Import-Module ../MasterScript/Script1.ps1 but it does not work and says it cannot find the module. If i say Import-Module C:\TFS\MasterScript\Script1.ps1 , it works fine. What am i missing here? 回答1: When you use a relative path, it

Use PowerShell to generate a list of files and directories

[亡魂溺海] 提交于 2019-12-20 09:36:27
问题 I'm writing a PowerShell script to make several directories and copy a bunch of files together to "compile" some technical documentation. I'd like to generate a manifest of the files and directories as part of the readme file, and I'd like PowerShell to do this, since I'm already working in PowerShell to do the "compiling". I've done some searching already, and it seems that I need to use the cmdlet "Get-ChildItem", but it's giving me too much data, and I'm not clear on how to format and

Creating Zip files using PowerShell

岁酱吖の 提交于 2019-12-20 07:23:14
问题 I have these below files at a location C:\Desktop\Mobile. Apple_iphone6.dat Apple_iphone7.dat Samsung_edge7.dat Samsung_galaxy.dat Sony_experia.dat Sony_M2.dat I need to create a script that writes the similar files into a single zip. So files Apple_iphone6.dat and Apple_iphone7.dat must be into single zip. So the final zip files created would be: Apple_Files_Timestamp.zip Samsung_Files_Timestamp.zip Sony_Files_Timestamp.zip I tried this Get-ChildItem C:\Desktop\Mobile -Recurse -File -Include

Power shell Script execution from the AD on the all domain joined machines

烂漫一生 提交于 2019-12-20 07:21:59
问题 I have written a power shell script for downloading and executing the binary file that I want to deploy on more than 500 machines. I have already an active directory configured and all the machines in my network are on the domain. Some can please tell me that how I can execute this power shell script on the domain connected machines from the active directory like we deploy an MSI file from the AD. Thanks 来源: https://stackoverflow.com/questions/41525651/power-shell-script-execution-from-the-ad

Mouse event don't work after first timer Tick

混江龙づ霸主 提交于 2019-12-20 06:29:41
问题 I'm using powershell to develop a little tool with graphic interface and I'm going crazy with this issue... For example: I have a label on a form that display "real-time" status of a ping. In the same time, if you click on the label, a popup message is displayed. function GoogleStatus ($Label) { $Google = "www.google.com" If (Test-Connection -ComputerName $Google -Count 1 -Quiet) {Label.Text = "Yes"} else {Label.Text = "No"} } function HelloMsg { [System.Windows.Forms.MessageBox]::Show("Hello

How do I run a Powershell script from PHP

时光总嘲笑我的痴心妄想 提交于 2019-12-20 06:22:13
问题 I wrote one line of powershell script that downloads DHCP lease data. when i run it from powershell it works (exports the data into a csv file). but if i run the same code from php it exports an empty csv file. The powershell script and php code id below. DhcpServerv4Lease -ComputerName "HAP2000-11" -ScopeId 10.10.10.0 | Select-Object -Property IPAddress, Clientid, Description, HostName | Export-Csv -Path ("C:\wamp64\www\new.csv") php code <?php if(isset($_POST['updateDHCP'])){ shell_exec(

Replace placeholders with actual values in PowerShell dictionary

别来无恙 提交于 2019-12-20 05:13:31
问题 Following is the sample xml file: <configuration> <environment id="Development"> <type>Dev</type> <client>Arizona</client> <dataSource>Local</dataSource> <path>App_Data\%%type%%\%%client%%_%%dataSource%%</path> <targetmachines> <targetmachine> <name>Any</name> <remotedirectory>D:\Inetpub\Test</remotedirectory> </targetmachine> </targetmachines> </environment> </configuration> I'm trying to convert the above xml file into a PowerShell dictionary using following script. [System.Xml.XmlDocument]

Replace placeholders with actual values in PowerShell dictionary

萝らか妹 提交于 2019-12-20 05:13:03
问题 Following is the sample xml file: <configuration> <environment id="Development"> <type>Dev</type> <client>Arizona</client> <dataSource>Local</dataSource> <path>App_Data\%%type%%\%%client%%_%%dataSource%%</path> <targetmachines> <targetmachine> <name>Any</name> <remotedirectory>D:\Inetpub\Test</remotedirectory> </targetmachine> </targetmachines> </environment> </configuration> I'm trying to convert the above xml file into a PowerShell dictionary using following script. [System.Xml.XmlDocument]