powershell-3.0

Invoke-WebRequest GetSystemWebProxy()

☆樱花仙子☆ 提交于 2019-12-21 00:46:12
问题 Under PowerShell 2.0 I know that you can set the proxy you would like to use without knowing the exact proxy settings by doing something like the following: $proxy = [System.Net.WebRequest]::GetSystemWebproxy() $proxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials Now, my question is if I don't know the proxy settings can I use the above and combine it with a PowerShell 3.0 Invoke-WebRequest . Here's what I was hoping to be able to do: $proxy = [System.Net.WebRequest]:

Powershell - Get-ADComputer -properties memberof

偶尔善良 提交于 2019-12-20 07:11:23
问题 I am trying to find if any servers in our enviroment have NOT been applied to a particular group. I have a list of groups that we use to patch our Windows Servers on partiular days / nights / manual etc..., i am trying to check if any server in our enviroment was incorrectly put on the domain and missed this step - does not have a Patching Group Member. so far i i have: $servers = get-adcomputer -Filter 'ObjectClass -eq "Computer"' -properties * foreach ($server in $servers) { if($server

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(

How to Remove Special/Bad Characters from XML Using Powershell

好久不见. 提交于 2019-12-20 04:19:00
问题 I have an XML Files and I want to remove those Hexadecimal Characters Errors from the file below is the invalid characters: I don't know what does STX means and when i tried copying it to my clipboard and paste it in MS Work it shows some other value. How can I write a script in powershell to remove the above from my XML file. 回答1: The following regex will remove any invalid characters from XML by specifying a character class negating the entire set of valid unicode entries in an XML document

Powershell New-SmbMapping drives only accessible from Powershell [closed]

给你一囗甜甜゛ 提交于 2019-12-20 03:54:34
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . As I understand it, New-SmbMapping W: -RemotePath \\myserver\myfolder should do the same thing as net use w: \\myserver\myfolder . However, if I use net I am easily able to access the mapped drive from the Windows Explorer. On the other hand, if I use New-SmbMapping , it shows up if I run Get-SmbMapping , and I

Is it possible to attach an event to a PSObject?

五迷三道 提交于 2019-12-20 03:17:07
问题 Say I've a psobject like this : $o=New-Object PSObject -Property @{"value"=0} Add-Member -MemberType ScriptMethod -Name "Sqrt" -Value { echo "the square root of $($this.value) is $([Math]::Round([Math]::Sqrt($this.value),2))" } -inputObject $o Is it possible to attach an event so that the method Sqrt() is executed when the value attribute change ? ie : PS>$o.value=9 will produce the square root of 9 is 3 update As per @Richard answer this is the working recipe : $o=New-Object PSObject

Upload file to SharePoint 2010 using PowerShell and the OData API

…衆ロ難τιáo~ 提交于 2019-12-19 08:51:29
问题 I'm attempting to upload a file to SharePoint 2010: Function Add-Attachments() { [CmdletBinding()] Param( [Parameter(Mandatory=$True)] [int]$Id, [Parameter(Mandatory=$True)] [string[]]$Paths ) BEGIN {} PROCESS { $url = "http://server/resource/_vti_bin/listdata.svc/TheList($Id)/Attachments" Foreach ($Path in $Paths) { Write-Verbose "Attaching $Path ..." $headers = @{ 'Slug' = "TheList|$Id|$(Split-Path $path -Leaf)" } $Payload = @{filename=(Split-Path $path -Leaf);filecontent=([IO.File]:

Timeout error when running Invoke-RestMethod

心已入冬 提交于 2019-12-19 03:12:34
问题 I'm running the Invoke-RestMethod on PowerShell to invoke a Web API method. It works but after a minute or so, I get a timeout error. I'd really like for PowerShell to wait until the invoked method has completed. How do I do this? Thanks for any help. John PS C:\Test\TestScripts> .\Run_Automation 5.5.4.382.1 VERBOSE: GET http://server/api/Automation/GetAutomation?testName=5.5.4.382.1 with 0-byte payload Invoke-RestMethod : The operation has timed out. At C:\TeamCity\TeamCityScripts\Run

Concatenate files using PowerShell

北战南征 提交于 2019-12-18 18:54:05
问题 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? 回答1: 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 回答2: I would go this route: Get-Content file1.txt, file2