Scripting Blog [archived]

Formerly known as the "Hey, Scripting Guy!" blog

Hey, Scripting Guy! How Can I Handle Errors in a Windows PowerShell Script?

 (image) Hey Scripting Guy! When I used to write VBScripts, I liked the fact that I could use On Error Resume Next to handle any errors in my scripts. I have tried to find something like this in Windows PowerShell, but I have been unable to do so. Does Windows PowerShell have On Error Resume Next? -- OG (image) Hello OG, When I am ...

Hey, Scripting Guy! How Do I Create a CSV File from Within Windows PowerShell?

(image)   Hey Scripting Guy! I am having a problem trying to create a CSV file from within Windows PowerShell. I thought at first I could use the Write-Host cmdlet to do this. I came up with this command:Write-Host "col1,col2,col3" >> "C:fsotest.csv"But when I go to the test.csv file, it is empty. I am really stuck. I have spent ...

Hey, Scripting Guy! How Do I Get Data Out of a Function?

(image) Hey, Scripting Guy! I have been having problems with trying to understand functions in Windows PowerShell. I get that you use the Function keyword to create the function, but I do not know how to get information from the function back to the script. I have been able to make the functions work by using Write-Host from inside the ...

Hey, Scripting Guy! How Can I Both Save Information in a File and Display It on the Screen?

(image) Hey, Scripting Guy! You know the old commercial that goes, "Sometimes you feel like a nut, sometimes you don't"? Well, sometimes I want to save information from a script to a file, and sometimes I want to see it displayed to the screen. And at other times, I want both. In other words, I want my candy bar, and I want to eat it, too...