powershell

How to add the distrubtion group in Active Directory for a user?

How to add the distrubtion group from Powershell in Active Directory ? I have user in active directory and i want to add the user into particular group rather than going and server because that part is going to be outsourced. so how to add the distrubution group for particular user. ...

Powershell 1.0 - Renaming files fails when script is in a different directory

I am trying to batch rename old log files, but the script only works for me when the script is stored in the same folder as the log files. Here is the code: cls $file = gci E:\logs |? {$_.extension -eq ".log" |% {rename-item $_ ($_.Name + ".old")} When I run this script from E:\logs, it works just fine. However, when I run this scri...

How can I optimize my PowerShell - LDAP Query?

Hey guys, this one is out there for the PS gurus. I've created a script that reads from a CSV (or other dataset, but not posting that side) and creates users in my AD environment. Basically, whatever dataset is passed into the script will be processed, and then a user will be created if they do not exist. If the user exists in the AD al...

Strange Windows PowerShell 2.0 Behavior

Consider the following PowerShell script: function Alpha { # write-output 'Uncomment this line and see what happens.'; return 65; } function Bravo { $x = Alpha; $y = $x -eq 65; return $y; } $z = Bravo; echo $z; On my computer (which is running Windows XP SP3, .NET 4.0, and PowerShell 2.0 RTM), when the script is run, the script's ou...

How to reference .net assemblies using powershell

I am a C# .net developer/architect and I am learning powershell. I have the basics down packed and understand that it uses objects (.Net objects) and not just streams/text. I would like to be able to use powershell to call methods on my .net (C# library) assembies. How do I reference an assembly in powershell and use the assemlbY? ...

Access Exchange shared folder via powershell

Hi, I need to access a public Exchange folder from my machine using PowerShell. I've found a guide saying that Get-PublicFolder is what I need, but I get this error: The term 'Get-PublicFolder' is not recognized as a cmdlet, function, operable program, or script file. Verify the term and try again. Another guide suggests to add the e...

How to get only directories from get-childitem

I'm using PowerShell 2.0 and I want to pipe out all the subdirectories of a certain path. The command get-childitem c:\mypath -Recurse | ... outputs all files and directories, but I can't figure out how to filter out the files. I've tried using $_.Attributes to get the attributes but then I don't know how to construct a literal inst...

Send email via Powershell and Outlook

Hi, I have a .msg file on my filesystem. With powershell I can open a Outlook window with the message simply like this: Invoke-Item "MY MAIL.msg" How to change the subject and forward it to a given address via Powershell? Thanks in advance ...

PowerShell and MSBuild difference

I am new to both MSBuild and PowerShell and am trying to wrap my head around where these stand with respect to deploying ASP.NET applications. Can someone explain the difference? (I hope I am comparing apples and apples) ...

Powershell - Delete all non mp3 files

Hi I´m totally new to Powershell and wanted to write a script that deletes all non-mp3 files in a directory. My solution: get-childitem -Recurse | Where-Object {!($_.PSIsContainer)} | Where {$_.Extension -ne ".mp3"} | remove-item What can be improved in this statement or could be written in another way. Are there any problems wit...

How to read Powershell's debug stream from Powershell ?

Hi everyone, I am using Powershell 2.0 to write data to the Powershell's debug stream via Write-Debug function. Now I want to read that stream from the same powershell script. I tried to redirect the debug stream with "2>&1" but this works only for the error stream. Is there a way to read the Powershell debug stream from a powershell s...

Help with Windows PowerShell

I'm trying to access a method of text file, I use this first: Get-Item file.txt | get-member Then I would like to use the GetType() method, but it says it doesn't recognize file.txt as the name of a cmdlet,function,script file or operable problem. I need to access that or any other method :D ...

Is there some trick to AllowEmptyString

I've never been able to get the AllowEmptyString validation attribute to work. This: function Get-InputString( [parameter(mandatory=$true, position=0)][string][AllowEmptyString]$Str ) { $Str } Results in this: PS C:\> Get-InputString '' Unable to find type [AllowEmptyString]: make sure that the assembly containing this type ...

Converting Dos Command to Power Shell command.

I am working with PowerShell 2.0 with Psake 1.4 Here is the dos command that is running that I want to convert to PowerShell. "C:\Program Files\Borland\StarTeam 2005 R2\stcmd.exe" co -p "rubble.barney:dinno@HostName:4455/MySolution/WebApp" -is -fp "D:\FooBar\MySolution\Source" Notice that the path to stcmd has a space in it Notice ...

Powershell: IOException try/catch isn't working

I have a PS script that kicks off every 5 minutes to check for newly dropped folders and move them. Problem is that sometimes items within the folder are still being written to, in which case the script errors with: Move-Item : The process cannot access the file because it is being used by another process. [Move-Item], IOException +...

match all files in current directory

How do I achieve this in Windows using either Command-prompt or PowerShell? myprog * EDIT: I want to call myprog with each file in the current directory as an argument. ...

LogParser output and Powershell

Hello all, I am using the below PowerShell function to parse event logs that have been saved locally from a remote machine. Unfortunately, I cannot for the life of me figure out how to dump out to another format instead of just to the console window. When I insert an INTO statement into my SQL query I get the following error: Ex...

Powershell ,Read from a txt file and Format Data( remove lines, remove blank spaces in between)

Hi All, I am realy very new to powershell. I want to use powershell to read a txt file and change it to another format. Read from a txt file. Format Data( remove lines, remove blank spaces in between) Count of records ( "T 000000002" 9 chars) and then write the output to a new file. I have started powershell just 2 days ago so plz g...

How do you remove/delete a mount point in windows

Im looking for a way to remove a mount point (with either powershell/wmi/C#). I used the win32_volume to find what volumes have mount points and can find the path there (under name and caption) but i cant figure out how to delete those mount points. the win32_volume namespace has a method to create them but nothing to delete. the win32_m...

How can I use Invoke-WmiMethod to rename a computer

I am trying to call the Rename method on the Win32_ComputerSytem class using Invoke-WMI method. Using this syntax works fine (gwmi win32_ComputerSystem).Rename("NEWNAME") This also works fine for demo purposes Invoke-WmiMethod -path win32_process -Name create -ArgumentList notepad However, when i try the following, I get an error ...