powershell

Windows Powershell Script for testing a list of Redirected URL's

醉酒当歌 提交于 2021-01-28 22:13:07
问题 I want to a Windows PowerShell script that can test a list of URL's which are redirected. I want there status code and there target URL. I am getting for a single URL, however unable to get it for a list of URL's. If anyone can help me with the above. 回答1: Create a [WebRequest] object and set the AllowAutoRedirect property to $false : # You could read this list from a file if necessary $urls = @('http://stackoverflow.com/') foreach($url in $urls){ try{ # Create WebRequest object, disallow

Making a dynamic menu in Powershell

风格不统一 提交于 2021-01-28 21:11:40
问题 I'm trying to make a dynamic terminal menu that a user can select from in Powershell. At this point I have the code to display the menu, but not how to store the correct value in a variable: $ouCounter=1 Write-Host "`n Please Select OU" foreach ($ouEntry in ((Get-ADOrganizationalUnit -LDAPFilter '(name=*)' - SearchBase 'OU=Resources,DC=dept,DC=ad,DC=domain,DC=tld' -SearchScope OneLevel).Name)){ Write-Host $(" "+$ouCounter+".`t"+$ouEntry) $ouCounter++ } [int]$menuSelection = Read-Host "`n

Powershell - find file by 'file name' and rename based on CSV

限于喜欢 提交于 2021-01-28 21:10:58
问题 I have a set of files (OldName) in a Windows directory that I would like to rename (NewName) based on the following CSV file: OldName,NewName Sources/texas play_PGC_Cpgc_entryPoint_Cbp_1.f4v,01 Texas Play.f4v Sources/texas play_PGC_Cpgc_entryPoint_Dbp_1.f4v,02 First Song.f4v Sources/texas play_PGC_Cpgc_entryPoint_Ebp_1.f4v,03 Yellow Rose.f4v I'm not sure how to loop thru the CSV file... finding each file and replacing. Any thoughts would be appreciated. 回答1: First Import Your CSV file into

Missing API key when making API RestMethod Call After HTTP Basic authentication in Mailchimp

一曲冷凌霜 提交于 2021-01-28 20:43:52
问题 In PowerShell, I was able to log in using HTTP Basic authentication For Mail Chimp. $acctname = 'thisismyusername' $password = 'thisismyapikey' $params = @{ Uri = 'https://us14.api.mailchimp.com/3.0/'; Method = 'Get'; #(or POST, or whatever) Headers = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($acctname):$($password)"));} #end headers hash table } #end $params hash table $var = Invoke-RestMethod @params $var When I try to get basic info on list

Why does Chocolatey not install on this Vagrant box?

旧街凉风 提交于 2021-01-28 20:43:51
问题 I've installed chocolatey on my host machine (windows) using the powershell provision: Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) This is all fine and choco works on the host machine, but when I try to install it via vagrant ssh in the VM, it doesn't work at all. I've tried using scripts and adding them into the vagrantfile but with no luck. How can I get chocolatey on my windows vagrant VM? My vagrantfile # -*- mode: ruby -*- #

powershell populate combobox basing on the selected item on another combobox

本小妞迷上赌 提交于 2021-01-28 20:27:59
问题 This time I am stuck with another PowerShell GUI challenge. I have a Form that contains two different comboboxes (combobox1 and combobox2) What I want to do is: The first combobox to show a list of all the clients that I have and the second combobox to show all the different mailboxes that are available for the client that has been selected on the first combobox. Once again I don't know how to do it so I am asking you guys for advise. I managed to show a list of all the clients on the first

Getting a Java ProcessBuilder error when trying to run a Powershell script

…衆ロ難τιáo~ 提交于 2021-01-28 20:22:05
问题 I am trying to run a Powershell script (PS1) file from my java program. Here's my Java code : for ( ; ; ) { ProcessBuilder pb = new ProcessBuilder("C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -Command \"C:\\Java_Scratch2\\University.PS1"); Process p = pb.start(); p.waitFor(); } but when I try to execute, I get the following error in Windows CMD : C:\Java_Scratch2>java ParentClassBatchRunner java.io.IOException: Cannot run program "C:\Windows\System32\WindowsPowerShell\v 1.0

refreshing web page using powershell

痞子三分冷 提交于 2021-01-28 19:39:07
问题 I need to refresh only the current web page using powershell.But all the opened web pages are being refreshed.My code is here function Refresh-WebPages { param( $interval = 5 ) "Refreshing IE Windows every $interval seconds." "Press any key to stop." $shell = New-Object -ComObject Shell.Application do { 'Refreshing ALL HTML' $shell.Windows() | Where-Object { $_.Document.url } | ForEach-Object { $_.Refresh() } Start-Sleep -Seconds $interval } until ( [System.Console]::KeyAvailable ) [System

Converting PowerShell to Bash

旧街凉风 提交于 2021-01-28 19:32:57
问题 I need to convert the following PowerShell script to a Bash script. Could someone help me out? I'm really new to Bash and don't know how to manipulate the output from a curl command and then convert it to Json. $headers = @{"X-Octopus-ApiKey"="<api_key>"} $machine = Invoke-RestMethod "http://my.url/api/machines/discover?host=<ip_address>&type=ssh" -Headers $headers -Method Get $machine.Name = "<hostname>" $machine.Roles += "<role>" $machine.EnvironmentIds += "<environment>" $machine.Endpoint

Json unexpected character 

情到浓时终转凉″ 提交于 2021-01-28 19:26:19
问题 I am using below code to regenerate my Json using PowerShell, however it creates unexpected character before the start of the json { tag. <#$data = Get-Content -Raw -Path myfile.json | ConvertFrom-Json#> $data = @" { "stations": [ { "code": "1", "name": "United force" }, { "code": "2", "name": "Toowoon Bay Service Station" } ], "prices": [ { "stationcode": "1", "fueltype": "DL", "price": 126.97 }, { "stationcode": "1", "fueltype": "E10", "price": 118.92 }, { "stationcode": "2", "fueltype":