Dastari Posted November 7, 2007 Report Share Posted November 7, 2007 Hey guys, I'v just got the trial of PowerGadgets to see what I can do with it and have my first question. I am trying to monitor hard drive space on a remote server that is firewalled except for port 80. What I am doing is running a batch file on the server every minute that dumps the result of a "dir" into a text file on the web folder so I can read it remotly. As an example I wrote this quick function to give you an idea: function GetBytesFree(){ $Url = "http://www.somewebsite.com/dir.txt" $WebClient = New-Object System.Net.WebClient $Random = New-Object system.random $DirResult = $WebClient.DownloadString($Url+"?t="+$Random.nextdouble()) $BytesFree = $DirResult | find "bytes free" $BytesFree = $BytesFree.split(" ")[17] return [double]$BytesFree} PS C:\> GetBytesFree55153283072 Running this from the powershell console returns a double with the bytes free. It is correct and works fine. Now if i do a: PS C:\> GetBytesFree | out-gauge -type digital -floating I get a nice digital display with the number in it, this works fine. But what I want to be able to do is update this every minute. However when I try to do a: PS C:\> GetBytesFree | out-gauge -type digital -floating -refresh 0:1:0 I get the output the first time, but when 1 minute passes I get the following error from the gauge: Failed to connect to Data "The term 'GetBytesFree' is not recognised as a cmdlet, function, operable program, or script file. Verify the term and try again.' I realise that this is probalby not a PowerGadgets problem, but can anyone suggest a solution? Is it possible to put the function somewhere so it is exposed to the PowerGadget? Edit: After hunting around a bit more on the forums I found a post that mentioned when the -refresh is triggered a new instance of the Gadget with it's own runspace is created. I will have a play around and see what I can work out. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
IGSFX Posted November 7, 2007 Report Share Posted November 7, 2007 Try moving your script to a folder that appears in your PATH environment variable. This way PowerShell will find it regardless of your current path location. Quote Link to comment Share on other sites More sharing options...
marco.shaw Posted November 7, 2007 Report Share Posted November 7, 2007 So along the same lines as Ivan... Drop these lines in a .ps1 script $Url = "http://www.somewebsite.com/dir.txt" $WebClient = New-Object System.Net.WebClient $Random = New-Object system.random $DirResult = $WebClient.DownloadString($Url+"?t="+$Random.nextdouble()) $BytesFree = $DirResult | find "bytes free" $BytesFree = $BytesFree.split(" ")[17] [double]$BytesFree Then pipe that .ps1 to out-gauge. If you decide to leave the original code, and put all of that in a .ps1 script, make sure to invoke the function at the end of the .ps1. Either put the script in your path, or pass the full path to out-gauge. Quote Link to comment Share on other sites More sharing options...
Dastari Posted November 9, 2007 Author Report Share Posted November 9, 2007 Thanks for the help, Those solutions did work however I got the powershell console flashfor a quick second every time the refresh happened. In the mean time I had aplay around with the sidebar packaging tool and just pasted my code into thatas the data source. This actually worked phenomenally well and gave me a sidebar gadget to boot. *stares dreamily at his new sidebar gadget* Quote Link to comment Share on other sites More sharing options...
marco.shaw Posted November 15, 2007 Report Share Posted November 15, 2007 Those solutions did work however I got the powershell console flash for a quick second every time the refresh happened. Strange, I've never noticed the console flashing during refreshes. Is this still happening? Marco Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.