| Topic |
 |
RE: Radio Button help The function has its own scope and you were trying to reference variables out of scope which can be tricky, as you've seen, and isn't recommended as a best practice. Your approach looked more VBScript-like and less PowerShell. I find using Scriptbl ... by SAPIENScripter in General PowerShell on 24 Apr 2009 05:58 AM
|
 |
RE: Radio Button help The problem is that you are calling a function but not really passing it any parameters. Turn it into a script block like this: $SendConnector = { If ($SCSHradiobutton.checked){ # New-SendConnector -Name "External SMTP Connector" ... by SAPIENScripter in General PowerShell on 24 Apr 2009 04:26 AM
|
 |
RE: Calculating CPU Usage? The problem is that the site is mangling my code. It should be $z [ 0 ] but without the spaces. I've attached my script as a text file. Save it locally and rename with a .ps1 extension. by SAPIENScripter in General PowerShell on 30 Jan 2008 06:42 AM
|
 |
RE: Calculating CPU Usage? Your new code is better and certainly more PowerShell like. I've revised my sample and added inline comments to better explain what is happening. # Take a snapshot of running processes $ProcBefore=Get-Process #sleep for some specified number ... by SAPIENScripter in General PowerShell on 29 Jan 2008 04:14 AM
|
 |
RE: Calculating CPU Usage? I can't seem to get my CPU values to change so I tested by looking at the workingset property. Is this along the lines of what you are after? foreach ($p in $ProcBefore) { $procAfter | where {$_.id -eq $p.id} -OutVariable z | Out-Null if (($ ... by SAPIENScripter in General PowerShell on 28 Jan 2008 07:02 AM
|
 |
RE: Calculating CPU Usage? replace each sad face with a colon : and a ( by SAPIENScripter in General PowerShell on 28 Jan 2008 06:30 AM
|
 |
RE: Calculating CPU Usage? I think if you get in the PowerShell mindset, this will be a little easier to accomplish. Here's a more efficient PowerShell way to get you started. $ProcBefore=Get-Process sleep -Seconds 60 $procAfter=Get-Process foreach ($p in $ProcBe ... by SAPIENScripter in General PowerShell on 28 Jan 2008 06:29 AM
|
 |
RE: How to test for server permission This is probably a little more complete: Trap [System.UnauthorizedAccessException]{ return "Problem encountered with $strComputer- Access denied" } by SAPIENScripter in General PowerShell on 24 Jan 2008 07:21 AM
|
 |
RE: How to test for server permission I would try something like this: $errorActionPreference="SilentlyContinue" Trap [System.UnauthorizedAccessException]{ return "No Access Allowed" } $strQuery = get-wmiobject -credential $Cred win32_bios -computername $strComputer -ea STOP by SAPIENScripter in General PowerShell on 24 Jan 2008 07:19 AM
|
 |
RE: read sharePoint output, a text file, into hashtable Can you attach the file or at least a subset of it? by SAPIENScripter in General PowerShell on 17 Jan 2008 05:51 AM
|
 |
RE: Hiding PS Console Windows This is the solution I came up with: http://blog.sapien.com/current/2006/12/20/schedule-hidden-powershell-tasks.html by SAPIENScripter in General PowerShell on 17 Jan 2008 05:42 AM
|
 |
RE: Add additional SMTP address for user that uses user's alias name I thought this sort of thing was handled with Recipient policies. by SAPIENScripter in Exchange Server on 17 Jan 2008 05:26 AM
|
 |
RE: Remove WindowsEmailAddress? I can't find a way with the Exchange cmdlets to do this. Using the Quest cmdlets this should work: set-qaduser juser -objectattributes @{mail=''} by SAPIENScripter in Exchange Server on 17 Jan 2008 05:24 AM
|
 |
RE: A bit OT: Exchange 2003 CDOEXM and Vista I don't think re-registering the DLLs is sufficient. The Exchange 2003 Management tools won't run under Vista as you probably know which means it is unlikely any scripts using CDOEXM will likely fail. by SAPIENScripter in Exchange Server on 17 Jan 2008 04:50 AM
|
 |
RE: How to test for server permission Here's how you might use a general purpose trap: Trap { Return "Failed to connect" } gwmi win32_BIOS -computer File01 -cred $cred -ea stop You can define different traps based on different exceptions. by SAPIENScripter in General PowerShell on 17 Jan 2008 04:23 AM
|
 |
RE: read excel file If you can get rid of the first line, can you now import the file as a csv with the earlier suggestions? That would be the best way to get to an object. Otherwise, you would need to create a new custom object and then define new properties using A ... by SAPIENScripter in General PowerShell on 17 Jan 2008 04:20 AM
|
 |
RE: read excel file It appears the problem is that colored first line. Even though there is no text, the formatting must be throwing things off. On my test file, everything works even with an empty row at the top. But as soon as fill one of the first row cells, reading ... by SAPIENScripter in General PowerShell on 15 Jan 2008 01:17 PM
|
 |
RE: read excel file What version of Excel created this file? I got errors until I removed the first line and then re-saved it. by SAPIENScripter in General PowerShell on 15 Jan 2008 01:00 PM
|
 |
RE: read excel file Are "last name" and "first name" two different columns? If so, try this: $users+= $objRecordSet.Fields.Item("Last Name").Value+","+$objRecordSet.Fields.Item("First Name").Value by SAPIENScripter in General PowerShell on 15 Jan 2008 12:22 PM
|
 |
RE: read excel file Actually, is there something else in the first row? I can still read the spreadsheet as a database, even if if the first row is blank. by SAPIENScripter in General PowerShell on 15 Jan 2008 12:02 PM
|
 |
RE: read excel file Yes, that would cause a problem and actually explains all the issues we've had in trying to get this file converted to a CSV, for example. by SAPIENScripter in General PowerShell on 15 Jan 2008 11:52 AM
|
 |
RE: read excel file Make sure that the query string is selecting from the name of the worksheet tab. On mine it is Sheet1. Yours might be different. My approach assumes the first row are your properties or fieldnames, and that each row is a recordset. An advantage to ... by SAPIENScripter in General PowerShell on 15 Jan 2008 11:01 AM
|
 |
RE: read excel file How about trying to use ADODB to read the spreadsheet as a database? $objConnection= New-Object -com "ADODB.Connection" $file="c:\scripts\pirates.xls" $strQuery="Select * from [Sheet1$]" $objConnection.Open("Provider=Microsoft.Jet.OLEDB.4.0 ... by SAPIENScripter in General PowerShell on 15 Jan 2008 09:47 AM
|
 |
Datagrid Column Sort In my head, I know what direction to go, but whatever bug is plaguing me is making it hard to concentrate and I'm not getting very far in translating C# MSDN examples to PowerShell. Does anyone have a script sample that creates a datagrid form ... by SAPIENScripter in Working with .NET on 08 Jan 2008 07:00 PM
|
 |
RE: error when using -match operator -match is doing a regular expression match and the \ character is used in regular expressions. You need to escape it like this: If ($test -match "C:\\users") {write-host "OK"} by SAPIENScripter in General PowerShell on 03 Jan 2008 06:27 AM
|
 |
RE: Logical Operators in Powershell But of course. That's what I get for trying to post something without thinking clearly after a long day. There's a reason double negatives are a no-no in writing and they should be in scripting as well. :-) I agree that using Switch is the way ... by SAPIENScripter in General PowerShell on 02 Jan 2008 06:01 PM
|
 |
RE: Logical Operators in Powershell I prefer using Switch as well. Otherwise, use -and instead of -or. What is happening to expand on Brandon's point is that if $location equals "test1", then the other two comparisons will false and the -OR says, return TRUE if at least one of the co ... by SAPIENScripter in General PowerShell on 02 Jan 2008 04:22 PM
|
 |
RE: read excel file You need an extra command to strip out the blanks: $csv="c:\test\exported.csv" cat $csv | % {$_.replace(",,","")} | out-file c:\test\data.csv Now you can import data.csv and continue on as before. by SAPIENScripter in General PowerShell on 02 Jan 2008 10:50 AM
|
 |
RE: read excel file Now you're back to having to use the Excel COM object which is not the easiest thing in the world to work with. I'd still do the export to CSV, import into PowerShell and then use it from there. You should be able to include or exclude the csv fie ... by SAPIENScripter in General PowerShell on 02 Jan 2008 06:45 AM
|
 |
RE: Copy-Item versus XCOPY Nevermind. Now I see what you are talking about. The second time I copied, the files were getting sent to c:\temp\test_copy\test. by SAPIENScripter in General PowerShell on 02 Jan 2008 06:34 AM
|