powershell-2.0

My powershell script is printing a '1' before my expected output. Why?

瘦欲@ 提交于 2019-12-01 05:13:45
I wrote a simple powershell script that checks the number of tickets in a PSA service board and outputs the number of tickets and a color associated with it. However, my script is printing a '1' before the results. I am very new to powershell, and I can't seem to find the line that would print this. Any help would be appreciated. Thanks $SqlServer = "server" $SqlCatalog = "database" $SqlQuery = "SELECT COUNT(*) FROM v_rpt_Service WHERE Board_Name = 'Traige' AND Parent = ''" $SqlConnection = New-Object System.Data.SqlClient.SqlConnection $SqlConnection.ConnectionString = "Server = $SqlServer;

How can I call many URLs from a list asynchronously

邮差的信 提交于 2019-12-01 04:02:24
I have a few hundred thousand URLs that I need to call. These are calls to an application server which will process them and write a status code to a table. I do not need to wait for a response (success/fail), only that the server got the request. I also want to be able to specify how many concurrent jobs can be running at once as I haven't worked out how many concurrent requests tomcat can handle. Here's what I've got so far, basically taken from someone's else's attempt to do something similar, just not with url calls. The text file contains each url on its own line. The url looks like this:

Color words in powershell script format-table output

狂风中的少年 提交于 2019-12-01 04:00:13
Is it possible to color only certain words (not complete lines) for a powershell output using format-table. For example, this script scans a folder recursively for a string and then output the result with format-table. dir -r -i *.* | Select-String $args[0] | format-table -Property @{label="Line #"; Expression={$_.LineNumber}; width=6}, Path, Line -wrap It would be nice to be able to format the word we are searching for with a specific color, so that you can see exactly where it was found on the line. Rynant You could pipe the table into Out-String , then write the string in parts using Write

Write-Host => Export to a file

吃可爱长大的小学妹 提交于 2019-12-01 03:04:21
I have got a script with some commands such as Write-Host "Server1" . How can I export it to a file? When I tried with script > export.txt it didn't work. CB. Write-Host redirects the output only to the console. You can use Write-Output and redirect to a file ( > export.txt or pipe to Out-File export.txt ) In the extreme case when you absolutely need to redirect all output from a script, take a look to this cmdlet: Start-Transcript Get-Help Start-Transcript -full jon Z In PowerShell script > export.txt is syntactic sugar for script | Out-File -path export.txt . Write-Host sends the objects to

How to properly escape quotes in powershell v2?

扶醉桌前 提交于 2019-12-01 02:01:05
How do you properly escape quotes in powershell v2 (called from within a batch file)? I have tried: powershell -Command "(gc file1.txt) -join "`n" | Out-File file2.txt" and powershell -Command "(gc file1.txt) -join ""`n"" | Out-File file2.txt" and powershell -Command "(gc file1.txt) -join '"`n`" | Out-File file2.txt" but they all fail. Editor's note : The purpose of the command is to transform Windows CRLF line breaks to Unix LF-only ones, so as to create a file that will be processed on Linux. From a batch file ( cmd.exe ), you must \ -escape embedded " instances (even though PowerShell-

How can I call many URLs from a list asynchronously

浪子不回头ぞ 提交于 2019-12-01 01:12:36
问题 I have a few hundred thousand URLs that I need to call. These are calls to an application server which will process them and write a status code to a table. I do not need to wait for a response (success/fail), only that the server got the request. I also want to be able to specify how many concurrent jobs can be running at once as I haven't worked out how many concurrent requests tomcat can handle. Here's what I've got so far, basically taken from someone's else's attempt to do something

Powershell: Installing Modules on Target System

有些话、适合烂在心里 提交于 2019-12-01 00:27:30
When I do this - PS C:\> $env:psmodulePath.split(";") I get two folders - i.e. User Module Folder and System Module Folder . User Module Folder C:\Users\winUser1\Documents\WindowsPowerShell\Modules System Module Folder C:\Windows\system32\WindowsPowerShell\v1.0\Modules\ Now, when I am copying my psm1 files under system module folder, and trying to do import-module from ISE x86, the scripts are not getting loaded , but vice-versa is true - i.e. working from user module folder. But, in a production environment, I want any user to be able to execute the scripts. Any idea how to achieve the same ?

How to change the value of XML Element attribute using PowerShell?

折月煮酒 提交于 2019-11-30 21:35:03
问题 I am trying to access and change the particular attribute from XML tag XML: <office> <staff branch="Hanover" Type="sales"> <employee> <Name>Tobias Weltner</Name> <function>management</function> <age>39</age> </employee> <employee> <Name>Cofi Heidecke</Name> <function>security</function> <age>4</age> </employee> </staff> <staff branch="London" Type="Technology"> <employee> <Name>XXXX</Name> <function>gement</function> <age>39</age> From the above example I want to print branch attribute and

get Current user context

烂漫一生 提交于 2019-11-30 20:55:00
I've got problems with running a powershellscript from different locations (c# application, webservice...). I think it is a user context problem, so now I'm trying to find out under which user context powershell script is running. Is there any possibility log the current usercontext of the powershellscript? If you need to know the actual user: [reflection.assembly]::LoadWithPartialName("System.DirectoryServices.AccountManagement") [System.DirectoryServices.AccountManagement.UserPrincipal]::Current Use: [System.DirectoryServices.AccountManagement.UserPrincipal]::Current | gm to know available

Powershell: Installing Modules on Target System

回眸只為那壹抹淺笑 提交于 2019-11-30 20:40:43
问题 When I do this - PS C:\> $env:psmodulePath.split(";") I get two folders - i.e. User Module Folder and System Module Folder . User Module Folder C:\Users\winUser1\Documents\WindowsPowerShell\Modules System Module Folder C:\Windows\system32\WindowsPowerShell\v1.0\Modules\ Now, when I am copying my psm1 files under system module folder, and trying to do import-module from ISE x86, the scripts are not getting loaded , but vice-versa is true - i.e. working from user module folder. But, in a