powershell

What's a good way to write batch scripts in C#?

I would like to write simple scripts in C#. Stuff I would normally use .bat or 4NT .btm files for. Copying files, parsing text, asking user input, and so on. Fairly simple but doing this stuff right in a batch file is really hard (no exceptions for example). I'm familiar with command line "scripting" wrappers like AxScript so that gets ...

Calling powershell cmdlets from Windows batch file

Ok something so simple is just not working for me. I got a cmdlet that accepts a single parameter. I am trying to call a cmdlet within a Windows batch file. The batch file contains: cd %SystemRoot%\system32\WindowsPowerShell\v1.0 powershell Set-ExecutionPolicy Unrestricted powershell 'C:\convert-utf8-to-utf16.ps1 C:\test.txt' powersh...

A better Linux shell?

I use bash, and have done so for over a decade - but occasionally I wonder whether there has been any significant new developments in the world of Linux shells. A few years back Microsoft released PowerShell, which seemed very interesting. Is there any comparable innovation going on in Linux shells? ...

Setting "Log on as a service" and "Allow logon locally" with ADSI

I am trying to create a powershell script to automate user creation which is working great using ADSI. However I need to set the following properties and I am not sure how (or if ADSI can even do this): Log on as a service Allow logon locally Any ideas how to do this? ...

New-QADUser CmdLet not adding UserPrincipalName when called in PowerShell

I am trying to import users into AD using a CSV file, PowerShell, and Quest's AD CmdLets. When the users are added the UserPrincipleName is not added. Here is a sample CSV: FirstName,LastName,DisplayName,SamAccount,UserPrincipleName,Email FirstA,LastA,"First Last",FLastAL.ou1,[email protected],[email protected] Firs...

How to script FTP upload and download?

I'm attempting to make a batch file to upload a file to ftp server. If I type it in manually it works fine but when i run the batch file it halts after it's connected... it says connected to domain.com. 220 microsoft ftp server User(domain.com:(none)): then nothing else. What the heck is going on here? Below is my batch file: ftp ...

PowerShell MetaProgramming - Generating Advanced Functions

I am looking at dynamically building a bunch of Advanced Functions. I have been using New-PSScript for this but it doesn't allow for all the flexibility I am looking for. I was reading the man page for about functions advanced parameters and saw something about Dynamic Parameters at the end of the help article which gives the following...

How to do TDD and unit testing in powershell?

With MS ramming powershell into all new server products, I'm starting to (reluctantly) think I need to take it seriously. Part of "taking it seriously" is TDD. Have you found good methods to unit test power shell scripts? I've found samples of mocking from Mr Geek Noise - but I'd really like something like RhinoMocks. Brian Hartsock ha...

How to change SRS settings

Guys, could you help me please? I'm trying to change programmatically SRS's settings of my audio device. Well it's possible to use this command: rundll32.exe shell32.dll,Control_RunDLL mmsys.cpl,,playback but it still needs to push manually the "properties" button, go to the "SRS" tab and check the checkbox. Is it possible to make p...

StackOverflow reputation using PowerShell

How can I view my reputation with a PowerShell function ? ...

Using powershell to turn a folder structure into an XML file

I've been downloading a bunch of music the lately(yes yes, perfectly legal) Anyway, the random idea to turn the folderstructure into and XML file occured to me. I don't know what I'd do with it, but I'd like to be able to do it. So I turned to Windows Powershell. Turning any data into and XML file is done via: $P = "command to get dat...

Better than MSDOS batch files?

Is there something better than using MSDOS in a bat file to run commmand line operations and copy files around. I am running into the old chestnut "gotchas" with long file names etc - and for some reason the bat file wont pause - when I insert PAUSE in my script after running a command - it's just annoying. Whats better out there? Che...

Powershell.exe running the script in cli, or a wrapper?

Hi all! I have a third-party application that's extensible by adding exe-files that perform dataconversion etc. I've written an extension in Powershell that does the conversion I want, but I'm unable to get the third-party app to run my ps1, as it will only accept an .exe file as an extension. The app adds a filename as the first (and o...

How to add a script to the standard path in PowerShell?

Hi, how can i add a custom function / object to the standard array of recognized functions in PowerShell so that i can call it from the shell of PowerShell? Thanks ...

PowerShell Script to automate data entry to OpenOffice Calc Spreadsheet

Hi, I would like to be able to automate data entry to an Open Office spreadsheet using a PowerShell script, in the same way that Excel can be automated using PowerShell (see this Scripting Guy example). Is this possible? Thanks, MagicAndi ...

parameters and powershell functions

This is a total newb question. Loving powershell, but I'm definitely not getting something here: I'm creating a simple function to replicate a string x times. I am having some weird problem with the parameter -- it doesn't seem to be recognizing the second parameter. When I run the function, it returns an empty string. Further, I thi...

Powershell script to check application that's locking a file?

How will I do this in powershell. I like to check which process/application is using the file, so that I can close it. Thanks. ...

Email & Move Files Recursively

I am looking to create a script that emails and moves files recursively for all the files in a specified folder. So for each file it will: Email File1 move File1 Email File2 Move File2 Etc. Now when I run the script below I get the following message: The process cannot access the file because it is being used by another process. $fi...

Ouput redirection/capturing issue with Powershell and Try-Catch and external EXE

First off, either A) I'm not investigating into this hard enough or B) I've found a problem that requires some funky hack. By the way this is posh v1.0. Here it goes: A week or so ago I asked a question about redirecting the output from the exection of an EXE in powershell that was otherwise not being caught. I was swiftly presented wi...

Creating custom objects and using the output

I'm using the following to read one line from a whole load of text files and then summarize that information into one file. $computers = Get-content computers.txt $users = users.csv $header = 'Computer','User','Date','Time' Foreach ($computer in $computers) { $file = $computer +'.txt' $a = import-csv $file -Header $header | Select -...