Trouble with multiple Device ID's (Local Hard drives)

Ask your PowerShell-related questions, including questions on cmdlet development!
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.
This topic is 6 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Trouble with multiple Device ID's (Local Hard drives)

Post by jvierra »

What is on line 46?
User avatar
mtartaglia
Posts: 101
Last visit: Mon Dec 19, 2022 11:45 am

Re: Trouble with multiple Device ID's (Local Hard drives)

Post by mtartaglia »

Invoke-Sqlcmd -ServerInstance $sqlserver -Database $database -Username $sqluser -Password $sqlpass -Query $query
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Trouble with multiple Device ID's (Local Hard drives)

Post by jvierra »

Something is wrong with your SQL.
User avatar
mtartaglia
Posts: 101
Last visit: Mon Dec 19, 2022 11:45 am

Re: Trouble with multiple Device ID's (Local Hard drives)

Post by mtartaglia »

This is what I have but this doesn't look right.

$tmplt = @'
UPDATE dbo.NoendDate (EndDate, EndTime, EndSpace)
VALUES('{0}', '{1}', '{2}')
'@
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Trouble with multiple Device ID's (Local Hard drives)

Post by jvierra »

If any value is null the update sql will fail. Print the final statements to the console.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Trouble with multiple Device ID's (Local Hard drives)

Post by jvierra »

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}'"
User avatar
mtartaglia
Posts: 101
Last visit: Mon Dec 19, 2022 11:45 am

Re: Trouble with multiple Device ID's (Local Hard drives)

Post by mtartaglia »

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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Trouble with multiple Device ID's (Local Hard drives)

Post by jvierra »

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
User avatar
mtartaglia
Posts: 101
Last visit: Mon Dec 19, 2022 11:45 am

Re: Trouble with multiple Device ID's (Local Hard drives)

Post by mtartaglia »

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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Trouble with multiple Device ID's (Local Hard drives)

Post by jvierra »

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.
No idea what you are asking. You cannot use an ID in an update except in a where clause.

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.
This topic is 6 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked