powershell-2.0

PowerShell 2.0 and how to handle exceptions?

此生再无相见时 提交于 2019-12-03 13:19:07
问题 Why I get error message printed on the console when running these two simple samples ? I want that I get "Error testing :)" printed on the console insted of: Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA) At line:3 char:15 + Get-WmiObject <<<< -ComputerName possibly.nonexisting.domain.com -Credential (Get-Credential) -Class Win32_logicaldisk + CategoryInfo : InvalidOperation: (:) [Get-WmiObject], COMException + FullyQualifiedErrorId : GetWMICOMException

Loop through xml elements

别来无恙 提交于 2019-12-03 12:32:03
I have the following: $aMyArray = $null [xml]$userfile = Get-Content C:\AppSense\Scripts\AmPolicyConversion\AM_dev.xml $i = 0 FOREACH ($j in $userfile.ChildNodes){ FOREACH($k in $j.DocumentElement) { } $i = $i + 1 } I am trying to figure out how to loop through each element within powershell. Then check for an attribute of SID on the element. If exists get attribute value and put that value into an object and for the same element grab second attribute DISPLAYNAME and place into same object. We will create an array of objects. I know I am way off but hope you can help. Use XPATH instead to find

How to pass array of arguments to Powershell commandline

蹲街弑〆低调 提交于 2019-12-03 12:26:04
I am trying to pass array of arguments to powershell script file. I was trying to pass the commandline like this in command line. Powershell -file "InvokeBuildscript.ps1" "z:\" "Component1","component2" But it doesn't take the parameters it seems. What am i missing? how to pass array of arguments? Short answer: More double quotes could help... suppose the script is "test.ps1" param( [Parameter(Mandatory=$False)] [string[]] $input_values=@() ) $PSBoundParameters Suppose would like to pass the array @(123,"abc","x,y,z") Under Powershell console, to pass multiple values as an array .\test.ps1

Bug in New-WebServiceProxy cmdlet when using -Namespace?

拟墨画扇 提交于 2019-12-03 11:58:50
问题 So I ran into this exact problem: http://www.vistax64.com/powershell/273120-bug-when-using-namespace-parameter-new-webserviceproxy.html The gist of the issue is that when using the New-WebServiceProxy cmdlet AND the -Namspace parameter then you can't execute a method on the proxy with an argument of an autogenerated type. Something like this: // In the service public void DoSomething(DoSomethingRequest request) { ... } $proxy = New-WebServiceProxy -Uri "http://something.com/MyService.svc"

How to go fullscreen in PowerShell

╄→гoц情女王★ 提交于 2019-12-03 11:27:14
问题 Is there a way of making powershell appear in fullscreen? Not only maximize it over the screen, but hiding the top-bar as well? Also, since this is probably hard to do, how to maximize it according to current resolution? 回答1: Right click the top bar and select properties. Then depending on your screen resolution select the appropriate size. (under the layout tab). 回答2: Try typing the following command: mode 300 after the window opens 回答3: ALT + ENTER will full screen the powershell window in

How do I install PCSX Powershell module?

拈花ヽ惹草 提交于 2019-12-03 10:56:21
I'm running Windows 7 with PowerShell 2 installed. I've downloaded version 2.1 from here - http://pscx.codeplex.com/releases The Release notes say unblock the zip file - {which I did} extract the contents of the ZIP file to your $env:Home\Documents\WindowsPowerShell\Modules folder I was unsure what $env:Home was so a bit of searching determined that the release notes are expecting an environment variable called Home which doesn't exist on my machine. A bit more searching says use what is defined as ~ on my machine. So in a PS prompt I run cd ~ Which on my machine led to a network drive U: I

Copy-item Files in Folders and subfolders in the same directory structure of source server using PowerShell

不打扰是莪最后的温柔 提交于 2019-12-03 10:40:51
问题 I am struggling really hard to get this below script worked to copy the files in folders and sub folders in the proper structure (As the source server). Lets say, there are folders mentioned below: Main Folder: File aaa, File bbb Sub Folder a: File 1, File 2, File 3 Sub Folder b: File 4, File 5, File 6 Script used: Get-ChildItem -Path \\Server1\Test -recurse | ForEach-Object { Copy-Item -LiteralPath $_.FullName -Destination \\server2\test | Get-Acl -Path $_.FullName | Set-Acl -Path "\\server2

Compiling and running java application using powershell

╄→尐↘猪︶ㄣ 提交于 2019-12-03 10:14:28
问题 I am trying to compile and a sample Helloworld.java file. I have my jdk installed in C:\Program Files\jdk1.7\bin. And I have my Helloworld.java in C:\Helloworld.java I am actually a novice in both powershell and java. I got some examples from web regarding this but many of them advice to run it like this: java.exe -classpath $Env:CLASSPATH C:\Helloworld.java But when I give this in powershell I get an error called 'CLASSPATH' is not defined even after adding it in env variables. And when I

powershell v2 remoting - How do you enable unencrypted traffic

我们两清 提交于 2019-12-03 09:25:48
I'm writing a powershell v2 script that I'd like to run against a remote server. When I run it, I get the error : Connecting to remote server failed with the following error message : The WinRM client cannot process the request. Unencrypted traffic is currently disabled in the client configuration. Change the client configurati on and try the request again. For more information, see the about_ Remote_Troubleshooting Help topic. I looked at the online help for about _ Remote_Troubleshooting, but it didn't point me towards how to enable unecrypted traffic. Below is the script that I'm using that

Change powershell script to output without ellipses (…)

天涯浪子 提交于 2019-12-03 08:33:56
问题 I need some help with the output of the following script so the output doesn't show with the ellipses (...). I tried to insert "| Format-Table -Wrap -AutoSize" But I just don't seem to get it right. clear-host Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue $services = new-object system.collections.sortedlist $servers = (get-spfarm).servers foreach ($server in $servers) { foreach($service in $server.serviceinstances) { if ($service.status = "Online") { $s = $service