Trouble with multiple Device ID's (Local Hard drives)
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- mtartaglia
- Posts: 101
- Last visit: Mon Dec 19, 2022 11:45 am
Re: Trouble with multiple Device ID's (Local Hard drives)
Invoke-Sqlcmd -ServerInstance $sqlserver -Database $database -Username $sqluser -Password $sqlpass -Query $query
- mtartaglia
- Posts: 101
- Last visit: Mon Dec 19, 2022 11:45 am
Re: Trouble with multiple Device ID's (Local Hard drives)
This is what I have but this doesn't look right.
$tmplt = @'
UPDATE dbo.NoendDate (EndDate, EndTime, EndSpace)
VALUES('{0}', '{1}', '{2}')
'@
$tmplt = @'
UPDATE dbo.NoendDate (EndDate, EndTime, EndSpace)
VALUES('{0}', '{1}', '{2}')
'@
Re: Trouble with multiple Device ID's (Local Hard drives)
Here is how to write an update statement.
https://www.w3schools.com/sql/sql_update.asp
Sorry I wasn't paying attention because you assured me the code was working but only updating one drive. You need to be sure your SQL works.
$tmplt = "UPDATE dbo.NoendDate Set EndDate = '{0}', EndTime = '{1}', EndSpace = '{2}'"
https://www.w3schools.com/sql/sql_update.asp
Sorry I wasn't paying attention because you assured me the code was working but only updating one drive. You need to be sure your SQL works.
$tmplt = "UPDATE dbo.NoendDate Set EndDate = '{0}', EndTime = '{1}', EndSpace = '{2}'"
- mtartaglia
- Posts: 101
- Last visit: Mon Dec 19, 2022 11:45 am
Re: Trouble with multiple Device ID's (Local Hard drives)
That made some progress. Now all the EndSpace fields in three rows are identical numbers which is impossible since it is looking at different volumes and servers.
Re: Trouble with multiple Device ID's (Local Hard drives)
It is likely you are querying the same server repeatedly and that server has only one drive.
Add this line:
Write-Host $_.PsComputerName, $_.DeviceID, $_.Freespace
Add this line:
Write-Host $_.PsComputerName, $_.DeviceID, $_.Freespace
- mtartaglia
- Posts: 101
- Last visit: Mon Dec 19, 2022 11:45 am
Re: Trouble with multiple Device ID's (Local Hard drives)
Yes that is what I show while in the debugger with a breakpoint.
I think if I query on the ID field (auto incremented field) in the view, I may be able to use a where command in the sql statement.
I think if I query on the ID field (auto incremented field) in the view, I may be able to use a where command in the sql statement.
Re: Trouble with multiple Device ID's (Local Hard drives)
No idea what you are asking. You cannot use an ID in an update except in a where clause.miketartaglia wrote: ↑Wed Dec 27, 2017 1:56 pm Yes that is what I show while in the debugger with a breakpoint.
I think if I query on the ID field (auto incremented field) in the view, I may be able to use a where command in the sql statement.
What is what you show in the debugger?
You update statement will always update all records. You need to sit down and determine what it is you are trying to accomplish then run code at a prompt to test you ideas. We cannot decode what your purpose is or tell you how to accomplish it.
If you are trying to update the "start" records then you need to figure out some way to key the records. This comes under the heading of database design. Perhaps you can find a DBA in your company to help you with the database parts.