powershell-3.0

Background job to refresh data on a form while script is running?

让人想犯罪 __ 提交于 2019-12-01 23:02:26
问题 Hope some brave will help me ! I’m working from a few days now on a Powershell tool that display a dashboard on the screen corner to give some network “real-time” diagnostics of the computer. This dashboard can be minimized in the notification area. First, I created a function that get the diagnostics and display the status on the form. I tried to refresh data with a timer (See: Real Time Data With Powershell GUI). The problem was that my function took too much time to be executed and it

Background job to refresh data on a form while script is running?

久未见 提交于 2019-12-01 21:30:01
Hope some brave will help me ! I’m working from a few days now on a Powershell tool that display a dashboard on the screen corner to give some network “real-time” diagnostics of the computer. This dashboard can be minimized in the notification area. First, I created a function that get the diagnostics and display the status on the form. I tried to refresh data with a timer (See: Real Time Data With Powershell GUI ). The problem was that my function took too much time to be executed and it froze the interface. So buttons on the form were no more usable… (See: Mouse event don't work after first

Can you mimic PowerShell v3 once you have installed v4?

你。 提交于 2019-12-01 20:43:09
问题 I want to emulate PowerShell 3.0 From PowerShell v3 or v4 you can emulate v2 with this command: %windir%\system32\WindowsPowerShell\v1.0\PowerShell.exe -version 2 $Host reveals: Version: 2.0 However, in PowerShell 4 %windir%\system32\WindowsPowerShell\v1.0\PowerShell.exe -version 3 $Host now reports: Version: 4.0 (I was hoping for 3:0) Question: Is there any way of emulating PowerShell 3.0 from 4.0? 回答1: No, it's not possible. V4 is backwards compatible with V3, so any script written

How do I properly use the FolderBrowserDialog in Powershell

血红的双手。 提交于 2019-12-01 17:38:01
So I'm still fairly new to Powershell and I'm trying to write a script that allows the user to select a file or folder and then get back the security permissions for said folder/file. The problem is, I can't seem to get the file path to record as a variable to be used later. Here's what I have so far: Function Get-Folder($initialDirectory) { [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") $foldername = New-Object System.Windows.Forms.FolderBrowserDialog $foldername.rootfolder = "MyComputer" $foldername.ShowDialog() if($foldername.ShowDialog() -eq "OK") { $folder +=

Why is my boolean of value 0 returning true?

雨燕双飞 提交于 2019-12-01 17:30:13
I've been working on some PowerShell scripts and found something a little odd. I have a script that accepts 4 mandatory parameters: two strings and two Booleans. .\[scriptname] [string1] [string2] [bool1] [bool2] This works fine, and I've checked that they are all being passed correctly. However, I've found something rather strange when PowerShell asks for parameters; it sets both booleans to true. .\[scriptname] [string1] [string2] please enter bool1: 0 please enter boo2: 0 It then runs the script as if bool1 and bool2 were set to true, and not to what I've set them to. I have true passing in

Why is my boolean of value 0 returning true?

爷,独闯天下 提交于 2019-12-01 16:56:51
问题 I've been working on some PowerShell scripts and found something a little odd. I have a script that accepts 4 mandatory parameters: two strings and two Booleans. .\[scriptname] [string1] [string2] [bool1] [bool2] This works fine, and I've checked that they are all being passed correctly. However, I've found something rather strange when PowerShell asks for parameters; it sets both booleans to true. .\[scriptname] [string1] [string2] please enter bool1: 0 please enter boo2: 0 It then runs the

Modify web.config with powershell

让人想犯罪 __ 提交于 2019-12-01 16:38:33
I need to try to update a web.config file to change the IP address only of the web.config I have included the section of code Im looking at for powershell to script the change. <connectionStrings> <add name="connectionString" connectionString="provider=SQLOLEDB;Server=192.168.1.100;database=sample;Trusted_Connection=Yes" providerName="System.Data.OleDb" /> <add name="sqlConnectionString" connectionString="Data Source=192.168.1.100;Initial Catalog=sample;Trusted_Connection=Yes" providerName="System.Data.SqlClient" /> </connectionStrings> I would like a very simple solution to this just update

Modify web.config with powershell

纵饮孤独 提交于 2019-12-01 16:07:42
问题 I need to try to update a web.config file to change the IP address only of the web.config I have included the section of code Im looking at for powershell to script the change. <connectionStrings> <add name="connectionString" connectionString="provider=SQLOLEDB;Server=192.168.1.100;database=sample;Trusted_Connection=Yes" providerName="System.Data.OleDb" /> <add name="sqlConnectionString" connectionString="Data Source=192.168.1.100;Initial Catalog=sample;Trusted_Connection=Yes" providerName=

How can I add color to the machine name in the prompt of a PowerShell Remoting session?

筅森魡賤 提交于 2019-12-01 15:59:10
问题 To make it more obvious when I'm remoted to a live/production server, I thought it'd be handy to be able to colour the machine name I'm connected to when using remote PowerShell sessions. However, I can't see a way to do this... The server name prefix seems to be independent of the Prompt function, and even if I could use that, I'm not sure how I could define a new Prompt only for the duration of the session. Is there a way to customise this? Note: I don't want to color all server names the

Concatenate files using PowerShell

徘徊边缘 提交于 2019-12-01 14:57:49
I am using PowerShell 3. What is best practice for concatenating files? file1.txt + file2.txt = file3.txt Does PowerShell provide a facility for performing this operation directly? Or do I need each file's contents be loaded into local variables? If all the files exist in the same directory and can be matched by a simple pattern, the following code will combine all files into one. Get-Content .\File?.txt | Out-File .\Combined.txt I would go this route: Get-Content file1.txt, file2.txt | Set-Content file3.txt Use the -Encoding parameter on Set-Content if you need something other than ASCII