everyone. I am newbie to Powershell. So your help is much appreciated.
My question is the following. I have a powershell small script that provides me with server Start, Stop, Kill ... tasks.
Here's the command
PS P:\> Get-ScheduledTask -TaskPath "*$someString*" | Get-ScheduledTaskInfo | Select TaskName,LastRunTime,NextRunTime
TaskName LastRunTime NextRunTime
-------- ----------- -----------
Archive 10/14/2017 7:00:00 AM 10/21/2017 7:00:00 AM
Kill 10/15/2017 12:50:50 PM 10/22/2017 12:50:50 PM
Restart 10/20/2017 12:00:00 AM 10/23/2017 12:00:00 AM
Start 10/15/2017 1:00:00 PM 10/22/2017 1:00:00 PM
Stop 10/13/2017 5:30:30 PM 10/20/2017 5:30:30 PM
I would like to extract the value of LastRunTime that corresponds to Start and the value of NextRunTime that corresponds to stop, and have them converted to a String.
Thank you.
Not very useful in the requested OP format, but here you go
C:\> $TaskNames = "Start","Stop"
C:\> $data = Get-ScheduledTask -TaskName $TaskNames | Get-ScheduledTaskInfo
C:\> [string]"$(($data | sort)[0].LastRunTime) $(($data | sort)[1].NextRunTime)"
10/20/2017 08:15:15 10/21/2017 09:16:16
this will only work right if your task names are actually in alphabetical order. Change the indexes (numbers in []) if the sort comes out in a different order.
Related
Can we trigger snowflake task manually or enable to run at a specific day and time?
if the above is not feasible. Any other alternative ideas?
When using USING CRON the following format is accepted:
# __________ minute (0-59)
# | ________ hour (0-23)
# | | ______ day of month (1-31, or L)
# | | | ____ month (1-12, JAN-DEC)
# | | | | _ day of week (0-6, SUN-SAT, or L)
# | | | | |
# | | | | |
* * * * *
There is no year option, so something like this would work:
'USING CRON 0 9-17 * * SUN America/Los_Angeles'
every hour starting at 9 AM and ending at 5 PM on Sundays (America/Los_Angeles time zone)
Yes, it is possible to run task manually using
EXECUTE TASK
Manually triggers an asynchronous single run of a scheduled task (either a standalone task or the root task in a task tree) independent of the schedule defined for the task.
A successful run of a root task triggers a cascading run of child tasks in the tree as their precedent task completes, as though the root task had run on its defined schedule.
EXECUTE TASK <task_name>;
In sys.time_zone_info of MS-SQL server current_utc_offset is stored in Hour Format(HH:MM).
There is any possible way to convert that time into Minutes format?
Actual Result
name | current_utc_offset
---------------------------------------------------------
Syria Standard Time | +02:00
----------------------------------------------------------
Expected Result
name | current_utc_offset | Minute
----------------------------------------------------------------
Syria Standard Time | +02:00 | +120
----------------------------------------------------------------
Simplest way (avoiding creative string manipulation) is to (ab)use SWITCHOFFSET:
SELECT
name,
current_utc_offset,
DATEPART(TZOFFSET, SWITCHOFFSET('', current_utc_offset)) AS current_utc_offset_minutes
FROM sys.time_zone_info
If your really must have the sign with that in all cases and you can't handle that client-side (which I'd consider a better option), then FORMAT is your friend:
SELECT
name,
current_utc_offset,
FORMAT(DATEPART(TZOFFSET, SWITCHOFFSET('', current_utc_offset)), '+0;-0') AS current_utc_offset_minutes
FROM sys.time_zone_info
There are other approaches (AT TIME ZONE could be used on the time zone name, for example).
I am currently working with a nightly import that I need to create, but am not sure what the best route would be to update/insert into the current table. This is all done in MS SQL Server 2012 and pulling the Excel file from another server. I am trying to figure out how I can loop through the columns and pull out the data I need. If I could rearrange the data, I would but am currently stuck with what I have.
In my current table tblHW I have Columns such as PmpCount, , NumberStages, Pmpmodel_pmp1, serialnum_Pmp1, pmpModel_pmp2, Pmpmodel_pmp2, serialnum_pmp2, partnum_motor1, serialnumberMotor1, etc…. I apologize in advance for not being able to post a real table or a picture.
Example:
|Name | PmpCount| numstages| pmpmodel_pmp1| stages_pmp1| Sn_pmp1|
|AN 91-23G | 4| 500| FX2347| 250| 354197|
|BR DN 895R| 5| 521| D2442| 45| 875164|
|ALN 1-60J | 5| 521| H21342| 95| 594126|
|pmpmodel_pmp2| stages_pmp2| sn_pmp2| Partnum_mtr1| sn_mtr1|
|FX2347 | 250| 354198| NULL| NULL|
|FX17500 | 143| 102547| M7544| 4512241|
|FX17500 | 143| 458790| M7544| 4512364|
The information I want to move into tblHW comes from the tbl Pull_Down. Here is the setup:
|Name | Run_ID | Part1| SN1 | Attribute1_7|
|AN 21-919G| Oct 08, 2013 / 100845| BOD| NA| 3RD U|
|FR 55-013A| Oct 17, 2013 / 100853| Pmp| 2EA3A022| 78|
|FR 55-013A| Oct 01, 2014 / 101383| Cbl| N/A| REDALEAD|
|FR 43-223J| Apr 03, 2013 / 100594| BOD| NA| 3RD U|
|VH 204 | May 17, 2014 / 101145| BOD| 3RD U|
|Part2| SN2 | Attribute2_7| Part3 | SN3 | Attribute3_7|
|Pmp | 2EA3F379| 78| Pmp| 2EA3N380| 117|
|Pmp | 2EA3C020| 117| Pmp| 2EA3Y021| 117|
|MLE | J14312161| 120| BOD| N/A| 3RD U|
|Other| NA| Pmp| 2EA2X774| 78|
|BOD | NULL| Pmp| 2EA4F075| 38|
A bit more information. I am receiving this information in the form of five excel spreadhsheets each with over 400 columns. The columns giving me the biggest headache are the 20 part columns that I need to place into the SQL table.
I need to somehow move each row into the tblHW but need to do something like this:
The first row AN 21-919G needs to have SN1 to be inserted into sn_mtr1 since it is a BOD, SN2 into SN_pmp1 since it is a PMP, and SN3 into sn_pmp2 since it is the second PMP here. I also need to get the pmp count, in this case 2 and then add the attribute1_7 and attribute2_7 to put into numstages when the prts are PMP.
Situations like this is the whole purpose for SSIS to exist: Integration Services!
First one would question as to why the data you need is in Excel, and if there is a more direct route, one could exploit, as a linked server (if the source is another RDBMS).
Based in what information you provide, we make the following assumptions:
A) We have no control on the source output and we must import the data from Excel.
B) The files always have consistent columns (probably created by an automated process).
In SSIS you can easily create a source connection for the Excel file. If the Excel file name is dynamic, you can create a script to modify the connection string for that connection before importing data. Then set the destination connection to the SQL Server. The last step is creating a Data Flow Task where you can map the source to the destination columns.
Example:
I am going to write a powershell script that gets various statistics on the dir it is in.
If I do
get-childitem
I get this
d---- 06/23/2014 2:49 PM asdf;
-a--- 06/23/2014 2:49 PM 23 New Text Document - Copy (2).txt
-a--- 06/23/2014 2:49 PM 23 New Text Document - Copy (3).txt
-a--- 06/23/2014 2:49 PM 23 New Text Document - Copy (4).txt
-a--- 06/23/2014 2:49 PM 23 New Text Document - Copy (5).txt
-a--- 06/23/2014 2:49 PM 23 New Text Document - Copy.txt
-a--- 06/23/2014 2:49 PM 23 New Text Document.txt
And if I do
(get-childitem).count
I get
7
I want to be able to count the number of files in the directory as well as the number of folders. Any suggestions would be appreciated. thanks.
Well, you want two different things, so you're probably going to need to run two different commands. Count folders:
(GCI|?{$_.PSIsContainer}).Count
And then count files:
(GCI|?{!$_.PSIsContainer}).Count
You can do that using the following command:
$headers = #{ $true='Folder'; $false='File' }
Get-ChildItem |
Group-Object PSIsContainer |
Select-Object #{ Name="Type"; Expression={ $headers[$_.Name -eq $true] } }, Count
Or all in one line:
gci | group psiscontainer | select #{n="Type";e={#{$true='Folder';$false='File'}[$_.Name -eq $true]}}, Count
I am totally newbie to Access, I used to use Excel to handle my needs for a while.
But by now Excel has become too slow to handle such a big set of data, so I decided to migrate to Access.
Here is my problem
My columns are:
Number | Link | Name | Status
1899 | htto://example.com/code1 | code1 | Done
2 | htto://example.com/code23455 | code23455 | Done
3 | htto://example.com/code2343 | code2343 | Done
13500 | htto://example.com/code234cv | code234cv | Deleted
220 | htto://example.com/code234cv | code234cv | Null
400 | htto://example.com/code234cv | code234cv | Null
So I want a way to update Status of my rows according to numbers list.
For example I want to update Status column for multiple numbers to become Done
Simply I want to update "Null status" to become "Done" according to this number list
13544
17
13546
12
13548
13549
16000
13551
13552
13553
13554
13555
12500
13557
13558
13559
13560
30
13562
13563
Something like this
I tried "update query" but I don't know how to use criteria to solve this problem
In Excel I did that by "conditional formatting duplicates" -with my number list which I wanted to update-
Then "sort by highlighted color" then "fill copy" the status with the value
I know that Access is different but I hope that there is a way to do this task as Excel did.
Thanks in advance
From my understanding, You can try
Update TblA
Set TblA.Status="Done"
where Number in (13544,17,13546,....)
Or alternatively easy method is to pull these numbers in IN clause into its own table and use it like this
Update TblA
Set TblA.Status="Done" where Number in (select NumCol from NumTable )
or this solution may help you Here