powershell-v1.0

Powershell, trying to output only the path and lastwritetime on directories

I am trying to write a script that will output any directory that has not changed in over 90 days. I want the script to ONLY show the entire path name and lastwritetime. The script that I wrote only shows the path name but not the lastwritetime. Below is the script. Get-ChildItem | Where {$_.mode -match "d"} | Get-Acl | Format-T...

Building a Snap-in Targeting PowerShell V1 and PowerShell V2

How do I build a PowerShell snap-in to target PowerShell v1 and v2? Given that v1 and v2 can't be installed side by side how can I reference the appropriate assemblies and build against them? Inevitably as things go on I'm going to be adding new PowerShell v2 specific features. So I'm going to need separate product builds targeting diff...

PowerShell Get-Item question

I am new to PS. Here is an example of my function codes: function foo() { # get a list of files matched pattern and timestamp $fs = Get-Item -Path "C:\Temp\*.txt" | Where-Object {$_.lastwritetime -gt "11/01/2009"} if ( $fs -ne $null ) # $fs may be empty, check it first { foreach ($o in $fs) { # new ...

Determine Users Accessing a Shared Folder Using PowerShell

Hi, I need to determine the users/sessions accessing a shared folder on a Windows XP (SP2) machine using a PowerShell script (v 1.0). This is the information displayed using Computer Management | System Tools | Shared Folders | Sessions. Can anyone give me pointers on how to go about this? I'm guessing it will require a WMI query, bu...

Determine What Version of PowerShell is Installed?

Hi, How can I determine what version of PowerShell is installed on a computer, and indeed if it is installed at all? Thanks, MagicAndi ...

Powershell async launching

I have a powershell script which executes from a c# call (ex.. Process.Start(powershell.exe file.ps1);) notepad.exe filename this however seems to block script completion, as the event of completion is not fired until the notepad dialog is closed. Is there a way for me to start notepad.exe but let the script complete execution. Maybe...

Powershell: get-ChildItem recurse as a parameter

I am relatively new to PowerShell, so I am hoping this is simple, and I just missed it. I am looking to create a function that could toggle the ability to recurse in get-childItem. As a very basic example: ... param ( [string] $sourceDirectory = ".", [string] $fileTypeFilter = "*.log", [boolean] $recurse = $true ) ge...

Copy-Item copies directory as well as contents to UNC path

Im trying to take the conents of a folder and copy it to a another unis powershell 1.0. Pretty simple stuff and all works fine using Copy-Item $from $to -recurse if I am copying from a local folder to a local folder, however if the $to variable is a UNC path it seems to copy the $from directory, not just its contents eg $from = "c:\temp...

Passing string included dollar signs to -Replace Variable

I am trying to replace a sentence in .config file using powershell. ${c:Web.config} = ${c:Web.config} -replace '$BASE_PATH$\Test\bin`$Test_TYPE`$\WebTest.dll' , 'c:\program Files\example\webtest.dll' Everytime I try to run the above code I get "Invalid regular expression pattern: $BASE_PATH$\Test\bin\$Test_TYPE$\WebTest.dll" ...

Powershell v1 - deleteing all files & folders except in a named folder

I want to delete all the content and the children of a given root folder, however i want to keep some files (the logs), which all reside in a logs folder What is the elegant way of doing this in powershell. Currently i am doing it in multile steps, surely this can be done easily... i have a feeling my oo-ness/language bias is getting in ...

Powershell - Dynamic Function Call

With custom Powershell functions all function output is returned. I'm attempting to remove that limitation/confusion by writing a wrapper function that will return just $true or $false. However, I'm struggling with the dynamic function call . . . specifically passing the arguments. Note that both the function name and the function...

Permission issues across servers in powershell

I wish to have an automated process that basically deploys (copies) a asp.net web site in a CI situation. I have built the web site and I then want to copy the code to the web server. This powershell code is running on my build server. the build server is running under a defined service account and i have given that account full control ...

Using powershell to edit multiple XML files

How can I get a list of multiple XML files from a specified directory and for each file add an element under the second root node using powershell? Example: I want to add <LastName>SomeName</LastName> within the FIRST <Names> element: <People> <Names> <FirstName>someFirstName</FirstName> </Names> <Names> <FirstName>my...

How to pause a Powershell script until some external event has occurred?

I am using a Powershell 1 script to kick off a Python program, and I want to then pause the Powershell until the Python has completed its work. (I have complete ownership of the Python file.) What is the best way to go about this? ...

How can I get warning output from a PowerShell cmdlet programatically in v1.0?

Hi, I'm using PowerShell v1.0 (It is a requirement that I cannot use 2.0) and am having trouble trying to programatically capture the cmdlet output in the Warning stream. In Powershell 2.0 it's easy: var powerShell = PowerShell.Create(); powerShell.AddCommand(someCommand); powerShell.Invoke(); foreach (var warning in powerShell.Strea...

Why did a PowerShell script argument need to be copied to a local variable?

I have a very simple Powershell v1.0 script to kill processes by name: $target = $args[0] get-process | where {$_.ProcessName -eq $target} | stop-process -Force which works. However, when I just had get-process | where {$_.ProcessName -eq $args[0]} | stop-process -Force it wouldn't find any processes. So why does the argument need ...

64bit equivalent class for a wmi class "win32reg_addremoveprograms"?

My code below works perfectly on a 32-bit Windows machine, however it refuses to work on a 64-bit machine due to the 32-bit WMI class win32reg_addremoveprograms used in the code. Is there a 64-bit equivalent of this class? $ServerFile = "D:\SharePoint\Powershell\AddRemovePrograms\Machines.txt" $ServerList = Get-Content $ServerFile $Exc...

How to read the xml file and write its content into a plain text file?

How to read the below xml file and write its content into a plain text file? <!-- < config > < compare > < source >d:\demo\< /source > < destination >e:\demo\< / destination > < parameters > < parameter >FileName< /parameter> < parameter >Size< /parameter> < parameter>Date< /parameter> < /parameters > < /compare > < ...

PowerShell: Retrieve a specific internal XML element

Hi, I have an XML document with this structure: <Fruits> <Fruit> <Code>1</Code> <Name>Apple</Name> </Fruit> </Fruits> What is the best way to get a <Fruit> element by its code (or any other field) in PowerShell 1 code? (Not XPath, as it is supported in PowerShell 2 only) Thanks! ...

Problem with Copy-Item -force

Hi, This is part of my image-copy-script: Get-Childitem | where {$.Extension -eq ".png" -or $.Extension -eq ".gif" -or $_.Extension -eq ".jpg"} | Copy-Item -destination $dest -force It works fine, and it can overwrite files. Well, it can overwrite if the existing file have attribute R or A. Not when its blanked. Error in red text: "Co...