powershell

Can you remove an Add-ed Type in PowerShell again?

I'm currently writing a library in C# and was using PowerShell to quickly test it on some occasions. However, this prevents me from re-building the project as PowerShell obviously still has the DLL open. Is there a way of unloading the DLL again after adding it with Add-Type? The documentation doesn't seem to have clues on that and the ...

powershell function return

Hi everybody, I try to start a function of an script out of another script. I want to save the return into a variable but this doesn't work. script1.ps1: function test { return "hallo" } script2.ps1: ./script1.ps1; $p=test or $p = ./script1.ps1; test It seems that $p is null, but I don't know what's wrong. Can anybody please he...

Powershell import-csv with empty headers

I'm using PowerShell To import a TAB separated file with headers. The generated file has a few empty strings "" on the end of first line of headers. PowerShell fails with an error: "Cannot process argument because the value of argument "name" is invalid. Change the value of the "name" argument and run the operation again" bec...

Loading powershell script around 10000 times.

I have a powershell script that runs during an msbuild process and validates some stuff by extracting info from log files. The script loads 2 xml files and then does some validation from the data extracted from the log files. Usually the script takes on average 1 to 2 seconds to run. Loading the xml files takes around 800ms to run. Sinc...

command line arguments in Powershell

So the problem is, that when I run my basic script that simply mirrors whats is passed in on the command line, the arguments aren't separated in the way I would expect them to be. the basic code is: write-host "`$args`[0`] = $args[0]" write-host "`$args`[1`] = $args[1]" write-host "`$args`[2`] = $args[2]" and if i call the script a...

powershell: script with variable args

Hi everybody, I want to start a script1.ps1 out of an other script with arguments stored in a variable. $para = "-Name name -GUI -desc ""this is the description"" -dryrun" . .\script1.ps1 $para The args I get in script1.ps1 looks like: args[0]: -Name name -GUI -desc "this is the description" -dryrun so this is not what...

How to iterate the irregularly-named children of an Xml.XmlElement in Powershell?

I have an XML file of the following format: <xml> <data> <foo float="99.0"/> <bar float="12.0"/> <tribble bool="true"/> ... <flibble int="1"/> </data> </xml> If I fetch that data in Powershell, I can see all the child elements of data with a Get-Memeber: > $xmlData = [xml](Get-Content m...

Automate client addition of wireless network

I'm looking for a way to add a wireless network on a Windows 7 machine through Powershell or any other automated procedure. Has anyone done this with a Powershell script? This would save a lot of time in setting up a few hundred imaged machines I have to do. Thanks in advance. ...

Is it possible to create Windows PowerShell Cmdlets with F#?

Reading the Microsoft documentation for creating PowerShell Cmdlets, I notice there is no example code for F#; instead, there is a message saying that "This language is not supported or no code example is available.". Is F# not supported for creating Cmdlets, or aren't there any examples in F#? ...

How to replace multiple strings in a file using powershell

I am writing a script for customising a configuration file. I want to replace multiple instances of strings within this file, and I tried using powershell to do the job. It works fine for a single replace, but doing multiple replaces is very slow because each time it has to parse the whole file again, and this file is very large. The scr...

How can I get powershell exception descriptions into a string?

I want to have access to the same message that Powershell prints when you send an error record to the output stream Example: This is the exception message At C:\Documents and Settings\BillBillington\Desktop\psTest\exThrower.ps1:1 char:6 + throw <<<< (New-Object ArgumentException("This is the exception")); + Category...

Get UAC setttings using powershell

Is there a way to get the UAC status(including level) in windows 7 computer using powershell? ...

Finding matches in arrays of objects in Powershell

Hi, I'm using custom objects to hold the name and schema from a set of SQL Server objects. I put the objects into an array, then I get another set of objects and put those into another array. What I'd like to do now is find all exact matches between the two arrays. I'm currently using this: $filteredSQLObjects = @() foreach ($SQLObje...

Powershell -like expression from a SQL LIKE expression

I have a table in my database that includes some columns that are used for LIKE expressions in SQL. The process I'm working with uses those expressions to exclude certain SQL objects from processing. I'm now putting similar code in Powershell, but I'd like to keep the columns consistent. I'm going to need to do something along the lines...

Cmdlet Contention between PowerShell SnapIns

I ran into an issue while using both the Vmware PowerCLI and System Center Virtual Machine Manager snap-ins for PowerShell. They both contain similarly named cmdlets, like 'Get-VM' and 'Get-VMHost'. It appears that the last snap-in to load wins, so I added logic in my script to load & un-load the snap-in when I needed to get either VMw...

WPF and Powershell - Handling events

Can anyone point me in the right direction for some documentation about handling WPF UI events in Powershell? I want to know how to, for example, call a function when a CheckBox or Radio Button is changed. Cheers! Ben ...

Calling PowerShell from batch, and retrieving the new value of a temporary environment variable set in the script?

Hey guys! I hope the title is concise, but just in case: I am calling a PowerShell script from a batch file. I want the PowerShell script to set the value of an environment variable, and for that new value to be available in the batch file when the PowerShell script finishes. I know that it is possible to set an environment variable u...

$psise object in the console Powershell

Hi all, is possible to load the $psise object in the console? I want to open several files in ISE but doing >ise filename >ise filename2 just open the first one. Inside ISE i don't have that problem because i use the $psise object to open the file function qwe($file){ if(-not (Test-Path $file)){ New-Item -Name $file -ItemType fil...

Setting registry permissions error "Set-Acl : Requested registry access is not allowed."

I'm trying to set a registry permission to FullControl but keep getting this error. Everything works fine until the Set-Acl. What am I doing wrong? New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT $acl = Get-Acl HKCR:\CLSID\"{000C1090-0000-0000-C000-000000000046}"\InprocServer32 $newOwner = [System.Security.Princi...

Exception Handling in Powershell 1.0

I am using the following code to upload a file using PowerShell 1.0. How can I tell if the upload completed successfully or if there was an error? I need to delete the file if the upload was successful. What I have tried: 1. the trap clause. Cant seem to get this one to work. 2. Checking the return value of $webclient.UploadFile -- this...