powershell

powershell : how do you run a folder size summation?

My objective is to write a copy script which moves files from one directory "d:\aa1" to "d:\aa2" up to a specified size of another directory d:\bbb. In other words.. I'd like it to copy all files from d:\aa1 to d:\aa2 until the size of d:\aa1 is the same size or less than d:\bbb So far I have $lmt = get-childitem d:\bbb | measure-o...

How do you add a property to a function object on the PSDrive "function:"?

I've attempted using the $function:foo value and get-item function:foo. All attempts succeed in modifying the temporary function object, but the additional property is missing when reassigned to the stored function (either through $function:foo = ... or set-item function:foo ...). Here are the results of my attempts (all fail): Setup ...

Why Powershell Environment PATH is different than the actual Environment PATH?

I'm having this weird situation : My user's and system's PATH variable is different than the PATH in powershell. When I do : PS C:\$env:path C:\Windows\System32\WindowsPowerShell\v1.0\;c:\oldpath However this is not correct, it looks like it stuck on some old PATH variable of my system, so none of the udpates I've done on it didn't...

Replacing escape characters in Powershell

I have a string that consists of "some text \\computername.example.com\admin$". How would I do a replace so my final result would be just "computername" My problems appears to not knowing how to escape two backslashes. To keep things simple I would prefer not to use regexp :) EDIT: Actually looks like stackoverflow is having proble...

What is the best technology to use for automating a task using .net libraries?

Imagine that you need to develop and schedule an application/script to do the following:- Reference one or more .net assemblies Query the API, get some objects for each object call another method in the API What would you use? In the past I have created small console applications that do the above, but it seems a bit clumsy and over...

powershell exchange 2003 : query ActiveDirectory for activesync, office, and description?

I'm using powershell to pull a list of exchange 2003 users and based on the user's mailbox "LegacyDN", I was hoping to use an LDAP query to pull their activesyncenabled property (msExchOmaAdminWirelessEnable), description, and office; however, it doesn't seem to be coming up for me. any ideas? here is how i'm querying for the AD attri...

powershell exchange 2003 quest : is there a way to query activesyncenabled?

Using quest powershell on a Windows 2003 Server running Exchange 2003, is there a way to query a user's activesync or oma is enabled or disabled? EDIT: This is arguably a duplicate of your own question from Dec. 3, 2008. ...

How do I get the content of a SQL Stored Procedure in Powershell?

I'm perverted in the sense that I hate exploring code and database structures in a tree view and I'd much prefer using something like the Powershell for that. Most of the stuff I need to do in SQL is exploring, i.e. looking at what columns does a table have or what does a particular stored procedure do. Looking at table columns is as e...

How to get the actual size-on-disk of a file from PowerShell?

Hello: I am writing an administrative script, and I need to calculate the size of files on disk. These files are on a compressed NTFS volume. I can't use FileInfo.Length, because that is file size and not size on disk. For example, if I have a 100MB file, but it is only using 25MB due to NTFS compression, I need my script to return...

powershell quest : get-qaduser -identity guid doesn't work?

i start out by querying an exchange server 2003 with: POSH>get-wmiobject -class Exchange_mailbox -namespace Root\MicrosoftExchangeV2 -server srv02 to get the users. One of the properties available is the mailboxguid. so for testing, I run POSH> get-qaduser -identity <mailboxguid> however it doesn't work. is there something spe...

C# Powershell snapin not registering using installutil

I've got a really simple powershell script (see below). I've got installutil aliased using the following in my profile: set-alias installutil $env:windir\Microsoft.NET\Framework\v2.0.50727\installutil In powershell I simply: installutil assemplylocation.dll This returns successfully. (Install/Commit both complete successfully). Yet...

What is the point of MSBUILD/NANT if you are just going to write procedural code? Isn't Powershell better?

I am currently writing a deployment script in MSBUILD, and after downloading several extensions, I have found myself looking at the build file and thinking: What was the point in doing this in MSBUILD? This deployment script is completely procedural: stop website, delete folder, copy files, change permissions, start website, etc. There...

Find the number of lines in a project with powershell

I'm trying to find a way to count the total number of lines in all of the source files of a project I have. I've tried piping dir -r -name into measure-object -line, but that just counts the number of files I have. Does anyone have a script to do this? ...

Can I get && to work in Powershell?

&& is notoriously hard to search for on google, but the best I've found is this article which says to use -and. Unfortunately it doesn't give any more information, and I can't find out what I'm supposed to do with -and (again, a notoriously hard thing to search for) The context I'm trying to use it in is "execute cmd1, and if successfu...

How to reload user profile from script file in PowerShell

I want to reload my user profile from a script file. I thought that dot sourcing it from within the script file would do the trick, but it doesn't work: # file.ps1 . $PROFILE However, it does work if I dot source it from PowerShell's interpreter. Why do I want to do this? I run this script every time I update my profile and want to t...

PowerShell - Most Compact way of "Delete all files from this folder except one"

What is the most compact way of deleting all files from a folder except one file in a PowerShell script. I doesn't matter at all which file is kept, just as long as one is kept. I'm using the PowerShell 2 CTP. UPDATE: An amalgamation of all the answers so far... $fp = "\\SomeServer\SomeShare\SomeFolder" gci $fp |where {$_.mode -notm...

PowerShell, Web Requests, and Proxies

When making a simple web request is there a way to tell the PowerShell environment to just use your Internet Explorer's proxy settings? My proxy settings are controlled by a network policy(or script) and I don't want to have to modify ps scripts later on if I don't have to. UPDATE: Great info from the participants. The final script tem...

PowerShell vs. Unix Shells

I'm debating whether I should learn PowerShell, or just stick with Cygwin/Perl Scripts/Unix Shell scripts, etc. The benefit of PowerShell would be that the scripts could be more easily used by teammates that don't have cygwin; however, I don't know if I'd really be writing that many general purpose scripts, or if people would even use t...

Using Powershell to achive post build in VS based on assembly platform

I am trying to use Powershell to achive post build in Visual studio. I want to copy the appropriate dlls to the appropriate directories after the build based on the platform to which the assembly is targetted (i.e. x86 or x64). Does anyone know how to achieve this? ...

How can I use PowerShell to update build qualities on previous TFS Builds?

We are using TFSDeployer to listen to build quality changes and deploy to our staging environment when it transitions to "Staging". I'd like to have it go ahead and update all of the other builds that have a currently build quality of "Staging" to be "Rejected". This appears to be something that needs to happen inside the PowerShell sc...