Options
Powershell script will not work. Any suggestions?
This is the error message I receive...
Error: SELECT clause: Semantic Error: 1st argument of function REPLACE_CHR must be a STRING
Invoke-Item : Cannot find path 'C:\chart_testpc.gif' because it does not exist.
At C:\chart-driveSpace.V2.ps1:44 char:12
+ Invoke-Item <<<< .\"chart_"$serverName".gif"
+ CategoryInfo : ObjectNotFound: (C:\chart_testpc.gif:String) [Invoke-Item], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.InvokeItemCommand
Here is the Powershell script I am using...
begin {
# function found on sepeck's blog | Black Mountain
function Get-DriveSpace([string]$SystemName ) {
$driveinfo = get-wmiobject win32_logicaldisk -filter "drivetype=3 or drivetype=4" -computer $SystemName
$driveinfo | select deviceid, `
@{Name="FreeSpace";Expression={($_.freespace/1GB).tostring("0.00")}}, `
@{Name="DriveSize";Expression={($_.size/1GB).tostring("0.00")}}, `
@{Name="Percentfree";Expression={((($_.freespace/1GB)/($_.size/1GB))*100).tostring("0.00")}}
}
}
Process {
$logparser = "c:\Program Files\Log Parser 2.2\LogParser.exe"
$serverName = $_
if ($serverName -eq $Null) {
$serverName= $env:COMPUTERNAME
}
Get-DriveSpace $serverName | Export-Csv $env:temp"\temp.csv" -NoTypeInformation
& $logparser "select deviceid, TO_REAL (REPLACE_CHR (percentfree, ',', '.')) as purcentage into chart_$serverName.gif from $env:temp\temp.csv order by deviceID desc" "-o:chart" "-charttype:BarStacked" "-charttitle:Purcentage : FreeSpace by disk Server:$serverName" "-values:ON" "-categories:ON" "-maxCategoryLabels:100"
Invoke-Item .\"chart_"$serverName".gif"
}
Can anyone help?
Error: SELECT clause: Semantic Error: 1st argument of function REPLACE_CHR must be a STRING
Invoke-Item : Cannot find path 'C:\chart_testpc.gif' because it does not exist.
At C:\chart-driveSpace.V2.ps1:44 char:12
+ Invoke-Item <<<< .\"chart_"$serverName".gif"
+ CategoryInfo : ObjectNotFound: (C:\chart_testpc.gif:String) [Invoke-Item], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.InvokeItemCommand
Here is the Powershell script I am using...
begin {
# function found on sepeck's blog | Black Mountain
function Get-DriveSpace([string]$SystemName ) {
$driveinfo = get-wmiobject win32_logicaldisk -filter "drivetype=3 or drivetype=4" -computer $SystemName
$driveinfo | select deviceid, `
@{Name="FreeSpace";Expression={($_.freespace/1GB).tostring("0.00")}}, `
@{Name="DriveSize";Expression={($_.size/1GB).tostring("0.00")}}, `
@{Name="Percentfree";Expression={((($_.freespace/1GB)/($_.size/1GB))*100).tostring("0.00")}}
}
}
Process {
$logparser = "c:\Program Files\Log Parser 2.2\LogParser.exe"
$serverName = $_
if ($serverName -eq $Null) {
$serverName= $env:COMPUTERNAME
}
Get-DriveSpace $serverName | Export-Csv $env:temp"\temp.csv" -NoTypeInformation
& $logparser "select deviceid, TO_REAL (REPLACE_CHR (percentfree, ',', '.')) as purcentage into chart_$serverName.gif from $env:temp\temp.csv order by deviceID desc" "-o:chart" "-charttype:BarStacked" "-charttitle:Purcentage : FreeSpace by disk Server:$serverName" "-values:ON" "-categories:ON" "-maxCategoryLabels:100"
Invoke-Item .\"chart_"$serverName".gif"
}
Can anyone help?
Comments
-
Options
RobertKaucher Member Posts: 4,299 ■■■■■■■■■■
The problem is here:Get-DriveSpace $serverName | Export-Csv $env:temp"\temp.csv" -NoTypeInformation & $logparser "select deviceid, TO_REAL (REPLACE_CHR (percentfree, ',', '.')) as purcentage into chart_$serverName.gif from $env:temp\temp.csv order by deviceID desc" "-o:chart" "-charttype:BarStacked" "-charttitle:Purcentage : FreeSpace by disk Server:$serverName" "-values:ON" "-categories:ON" "-maxCategoryLabels:100" Invoke-Item .\"chart_"$serverName".gif"
I verified the function is working and output is getting to the temp.csv when the additional code from the aAmper's adn is removed.
I don't really know what that is supposed to do. I did not see it on the blog. Do you have a direct link? -
Options
Zoomer Member Posts: 126
-
Options
Claymoore Member Posts: 1,637
This could be a problem writing to the root of C: Try changing Invoke-Item .\"chart_"$serverName".gif" to something like Invoke-Item C:\Scripts\Output\"chart_"$serverName".gif". You will have to create the C:\Scripts\Output folder structure first.
You could also try running the script from a different location so the current working directory isn't the root of C:. Early on I got in the habit of using C:\Scripts with \Input and \Output subdirectories to make things easier and more organized.
You should also change the charttitle from Purcentage to Percentage if you plan on showing the results to anyone. -
Options
Zoomer Member Posts: 126
Claymore,
I tried that, but unfortunately I am still receiving the error. I have all the pre-req installed OWC11 and Logparser 2.2. Still can't figure out why it is not working... -
Options
Claymoore Member Posts: 1,637
Invoke-Item is just going to open the file. Can you verify if/where logparser is creating the .gif chart file? -
Options
Zoomer Member Posts: 126
It does not look like logparser is creating any gif chart file.
temp.csv is being created in c:\Documents and Settings\test\Local Settings\temp\temp.csv so that part looks ok. But it does not look like any chart file is being created at all. -
Options
RobertKaucher Member Posts: 4,299 ■■■■■■■■■■
It does not look like logparser is creating any gif chart file.
temp.csv is being created in c:\Documents and Settings\test\Local Settings\temp\temp.csv so that part looks ok. But it does not look like any chart file is being created at all.
Have you looked at using the Google Charts API for this? Very easy and there is a PoSh function out there somewhere for gening the code. -
Options
diggercoder Registered Users Posts: 1 ■□□□□□□□□□
Probably you have the same issue I had.
You are missing one or both the prerequisite:
1- logparser 2.2
2- OWC11 (Office Web Component)
the first is used to parse the csv created
the second is used to create the chart
I downloded both from internet, installed like any application and the script worked fine
good luck