I have built a form using PowerShell to help my kids learn French numbers. The form plays the French pronunciation of a random number from a section of an MP3 audio file that contains all French pronunciations of 0 to 100. This all works fine using:
$zMediaPlayer = New-Object system.windows.media.mediaplayer;
$zMediaPlayer.Open($zMediaFile);
. . . .
$zMediaPlayer.Position = New-Object System.TimeSpan(0, 0, 0, 0, $zStartAt);
$zMediaPlayer.Play();
Sleep -Milliseconds $zDuration;
$zMediaPlayer.Pause();
$zMediaPlayer.Stop();
. . . . .
$zMediaPlayer.Close();
I have seen mention of a "clock" property of System Media Player that allows both 'StartAt' and 'Duration' to be used in a 'TimeLine' to play a section of a media file:
Public property Clock Gets or sets the MediaClock associated with the MediaTimeline to be played.
But I cannot find how to use this type of functionality in a PowerShell script as I have another idea for a script where such functionality would be very useful. Can someone describe how to use this functionality, thanks.
Related
What I'm going to do is writing an script with python to take an excel file as an input and then read the number and description of interfaces of a switch which is written in there , and then ssh to a cisco switch and change the description with the values added before in excel .
could any body give me a hint?
Try checking netmiko module. I was able to do something close to what you require using netmiko but now I use ansible ios_command which is a lot more easier for a non programmer network engineer.
Start with Paramiko or Netmiko , Netmiko is a bit better version. I would also just rethink about the actual project where instead of thinking about one switch think about all of them and see if you have some universal thing which you need to do in all of your switches instead of one.
For this project you could do below.
1 . save date in CSV
2 . Open CSV file
3. Create a dictionary and Save interface name as key , and description as values
4. Create a list where you can save all your keys --> l = d.keys()
4. SSH to the sw via paramiko/Netmiko .
5. Run a loop in the list l
on each iteration send below commands
interface l[i]
description d[l[i]]
this will translate to below
interface eth1/1
description d['eth1/1'] ( d['eth1/1'] will be value/description of whatever you are gonna get from CSV)
If you really try to learn python then its a good start however if you are on a time crunch Ansible is easier option
I need to open URL in Microsoft Edge (on Windows 10). When I invoke
start shell:AppsFolder\Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge http://www.google.com
then Microsoft Edge is started correctly but it doesn't open the given URL (www.google.com, in this case). It opens Bing search where the given URL is used as a search term instead.
The following method should work via Command Prompt (cmd):
start microsoft-edge:http://www.cnn.com
Windows 10: Create a shortcut with this destination:
%windir%\system32\cmd.exe /c "start microsoft-edge:https://twitter.com"
and a shortcut:
C:\Windows\System32\cmd.exe /c start shell:AppsFolder\Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge http://localhost:6516
I too was wondering why you can't just start microsoftedge.exe, like you do "old-style" applications in windows 10. Searching the web, I found the answer -- it has to do with how Microsoft implemented "Universal Apps".
Below is a brief summary taken from that answer, but I recommend reading the entire entry, because it gives a great explanation of how these "Universal Apps" are being dealt with. Microsoft Edge is not the only app like this we'll be dealing with.
Here's the link: http://www.itworld.com/article/2943955/windows/how-to-script-microsofts-edge-browser.html
Here's the summary from that page:
"Microsoft Edge is a "Modern" Universal app. This means it can't be opened from the command line in the traditional Windows manner: Â Executable name followed by command switches/parameter values. But where there's a will, there's a way. In this case, the "way" is known as protocol activation."
Kudos to the author of the article, Stephen Glasskeys.
All the other solutions work for Microsoft Edge (legacy) and on Windows 10 only.
As of 2020, it will be discontinued and replaced by Microsoft Edge (Chromium based).
The solution that works with the new Edge on Windows 7, 8 and 10 is :
start msedge URL
Source :
https://en.wikipedia.org/wiki/Microsoft_Edge#Anaheim_(2019%E2%80%93present)
https://learn.microsoft.com/en-us/deployedge/microsoft-edge-sysupdate-windows-updates
While the accepted answer is correct, it has the unwanted artifact of flashing a console window when running from a non-console application.
The solution I found works best, which is only mentioned here in a comments to the question, is the following command line:
explorer.exe "microsoft-edge:<URL>"
Keep in mind that if contains the % sign you will need to type %% as Windows uses the symbol for variable expansion.
Hope someone finds this helpful.
Personally, I use this function which I created and put in my profile script ...\Documents\WindowsPowerShell\….profile, feel free to use it. As I am from the UK, I prefer to go to .co.uk where possible, if you are from another area, you can add your own country code.
# Function taking parameter add (address) and opens in edge.
Function edge {
param($add)
if (-not ($add -contains "https://www." -or $add -contains "http://www.")) {
if ($add[0] -eq "w" -and $add[1] -eq "w" -and $add[2] -eq "w") {
$add = "https://" + $add
} else {
$add = "https://www." + $add
}
}
# If no domain, tries to add .co.uk, if fails uses .com
if (-not ($add -match ".co" -or $add -match ".uk" -or $add -match ".com")) {
try {
$test = $add + ".co.uk"
$HTTP_Request = [System.Net.WebRequest]::Create($test)
$HTTP_Response = $HTTP_Request.GetResponse()
$add = $add + ".co.uk"
} catch{
$add = $add + ".com"
}
}
Write-Host "Taking you to $add"
start microsoft-edge:$add
}
Then you just have to call: edge google in powershell to go to https://www.google.co.uk
I would like to recommend:
Microsoft Edge Run Wrapper
https://github.com/mihula/RunEdge
You run it this way:
RunEdge.exe [URL]
where URL may or may not contains protocol (http://), when not provided, wrapper adds http://
if URL not provided at all, it just opens edge
Examples:
RunEdge.exe http://google.com
RunEdge.exe www.stackoverflow.com
It is not exactly new way how to do it, but it is wrapped as exe file, which could be useful in some situations. For me it is way how to start Edge from IBM Notes Basic client.
Looks like things have changed and the previous solution doesn't work anymore.
However, here is the working command to launch CNN.com on Microsoft Edge:
microsoft-edge:http://www.cnn.com
I want to complement other answers here in regards to opening a blank tab in Microsoft Edge from command-line.
I want to add an observation from my end. Windows doesn't detect the command microsoft-edge if I remove the trailing colon. I thought colon would be required only when I've to provide the target URL to open e.g. when I've to open a blank tab. But that's not the case. Color (:) is required all the time.
How to open a blank tab in Microsoft Edge?
From Run prompt (press Window logo + R):
microsoft-edge:about:blank
microsoft-edge:
msedge
From Command(cmd.exe) prompt:
start microsoft-edge:about:blank
start microsoft-edge:
start msedge
You can also initiate a search using Edge from run prompt. Let's say I've to search Barack Obama then fire below command on run prompt-
microsoft-edge:Barack Obama
It starts Microsoft's Bing search website in Edge with Barack Obama as search term.
It will do more or less the same thing in good old dos script fashion
set add=%1
if %add%$ ==$ set add="about:blank" && goto launch
rem http://
set test=%add:~0, 7%
if %test% == http:// goto launch
rem ftp://
set test=%add:~0, 6%
if %test% == ftp:// goto launch
rem https://
set test=%add:~0, 8%
if %test% == https:// goto launch
rem add http
set add=http://%add%
:launch
start microsoft-edge:%add%
microsoft-edge:http://google.com (open google as desired)
microsoft-edge: (just open)
I have a vendor that supplies their documentation library as a series of PDF files (and some CHM files) and include a .PDX catalog also.
I want to write a powershell script to front end it (using either powershell forms, or hosting powershell in asp.net).
I'm in the early stages, I've worked out how to get document information from the PDF stream (the xmpmeta XML metadata block near the end of the PDF file - one of the few streams in the file that's in plaintext) which looks like this:
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 4.2.1-c043 52.372728, 2009/01/18-15:08:04
"><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:Description rdf:about="
" xmlns:pdf="http://ns.adobe.com/pdf/1.3/"><pdf:Producer>GPL Ghostscript 8.64</pdf:Producer><pdf:Keywo
rds>86000056-413</pdf:Keywords></rdf:Description><rdf:Description rdf:about="" xmlns:xmp="http://ns.ad
obe.com/xap/1.0/"><xmp:ModifyDate>2011-03-03T17:38:34-05:00</xmp:ModifyDate><xmp:CreateDate>2011-01-28
T23:12:07+05:30</xmp:CreateDate><xmp:CreatorTool>PScript5.dll Version 5.2</xmp:CreatorTool><xmp:Metada
taDate>2011-03-03T17:38:34-05:00</xmp:MetadataDate></rdf:Description><rdf:Description rdf:about="" xml
ns:xmpMM="http://ns.adobe.com/xap/1.0/mm/"><xmpMM:DocumentID>6cb2263d-2d61-11e0-0000-1390d57dcfcb</xmp
MM:DocumentID><xmpMM:InstanceID>uuid:1a0e68ba-14ad-4a03-b7a1-0a0e127b8753</xmpMM:InstanceID></rdf:Desc
ription><rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/"><dc:format>applicati
on/pdf</dc:format><dc:title><rdf:Alt><rdf:li xml:lang="x-default">I/O Subsystem Programming Guide</rdf
:li></rdf:Alt></dc:title><dc:creator><rdf:Seq><rdf:li>Unisys Information Development</rdf:li></rdf:Seq
></dc:creator><dc:description><rdf:Alt><rdf:li xml:lang="x-default">ClearPath MCP 13.1,Application Dev
elopment,Administration,ClearPath MCP</rdf:li></rdf:Alt></dc:description></rdf:Description></rdf:RDF><
/x:xmpmeta>
using the following code (powershell v3, in v2 you need to select and expand the properties thus [string]$title = ($rdf.GetElementsByTagName('dc:title')| Select -expand Alt|Select -expand li)."#text"):
$file = ".\Downloads\68698703-007\PDF\86000056-413.pdf"
#determine what line in file the xmpmeta string starts
[int]$startln = (select-string -pattern '^<x:' $file).ToString().Split(":")[2]
#determine what line in file the xmpmeta string ends
[int]$endln = (select-string -pattern '^</x:' $file).ToString().Split(":")[2]
$startln--
#grab the xmpmeta and cast as type xml
[xml]$xmp = (gc $file)["$startln".."$endln"]
[xml]$rdf = $xmp.xmpmeta.InnerXml
#get title/creator/description element text
[string]$title = $rdf.GetElementsByTagName('dc:title').Alt.li."#text"
[string]$creator = $rdf.GetElementsByTagName('dc:creator').Alt.li."#text"
[string]$description = $rdf.GetElementsByTagName('dc:description').Alt.li."#text"
That's crucial because the filenames are in the format 12345678-123.pdf, the actual title is in the metadata itself, as well as document category etc.
So, I can produce a list of documents (displaying their proper titles, not the real filename) and allow them to be launched, but I also want to be able to search in all the documents using PDX file, but it's by no means plaintext!
I guess I could use one of a number of tools out there to convert each PDF into text, search it, repeat for each document and then return results for each document.
But, it strikes me that Adobe Reader already does that, so can I either start AcroRd32.exe with switches that will start the search, with search terms I've passed in to the AcroRd32 program, or can I use Adobe Search.API from within Powershell?
Any ideas specifically on automating load of the .PDX in Adobe Reader and firing off the search, or using adobe's API in powershell?
EDIT:
I can now launch acrobat from command line and search (so could mimic this in powershell) but the search only works when searching a PDF, not a PDX catalog. Both bring up the search pane, but only in a PDF document does the search field get populated and the search executed.
C:\Program Files (x86)\Adobe\Reader 10.0\Reader>AcroRd32.exe /A "search=trim" "P:\Doc Library\PDF\00_home.pdx"
Or
C:\Program Files (x86)\Adobe\Reader 10.0\Reader>AcroRd32.exe /A "search=trim" "P:\Doc Library\PDF\86000056-413.pdf"
Regards,
Graham
This is an old post, but be aware that the searching you do is potentially dangerous and that there is a better way to find the XMP metadata in a PDF file. XMP was designed specifically to be "findable" by text search. To that purpose it has a well defined begin and end code defined that is in there specifically so that you can extract the XMP data without having to parse the PDF format (or any other format the XMP metadata blob might be embedded in.
You can download the XMP specification here: http://www.adobe.com/devnet/xmp.html. Part 1 is the part where the explanation about XMP Packets explains how a text scanner can find the XMP packet with more accuracy.
Finally, PDF has an additional quirk that allows it to be incrementally updated. This might cause multiple XMP packets to appear in the file (where the last packet is normally the correct one). But annoyingly when the PDF is exported from applications like InDesign, images in the PDF (and other objects) might also have their own "object" XMP attached to it.
So consider where your files come from and how many strange things you might encounter and you want to provision for. But reading the XMP specification is not a bad idea for sure.
I can run the following to get the current crawls and from there determine the last crawl completed date.
# Get the Search App from Sharepoint
$searchApp = Get-SPEnterpriseSearchServiceApplication "My Search Service"
Get-SPEnterpriseSearchCrawlContentSource -SearchApplication $searchapp
$contentsource = Get-SPEnterpriseSearchCrawlContentSource "MyCrawl" -SearchApplication $searchApp
$contentsource.CrawlCompleted
But this is the last time any crawl completed. I want the date of the last Full crawl.
I can see the information in the crawl History. But when I try and get the crawl history (see http://blogs.msdn.com/b/carloshm/archive/2009/03/31/how-to-programmatically-export-the-crawl-history-to-a-csv-file-in-powershell.aspx) using the below I don't seem to get an object I can really work with (its one big string container as far as I can tell) and it is full of IDs.
$s = new-Object Microsoft.SharePoint.SPSite("http://portal");
$c = [Microsoft.Office.Server.Search.Administration.SearchContext]::GetContext($s);
$h = new-Object Microsoft.Office.Server.Search.Administration.CrawlHistory($c)
I was hoping to get an object that represents the crawl history which I could then filter on crawl name and Type = full.
I have searched around and can't find an answer anywhere. (Note also that the CrawlHistory class is being deprecated).
Any thoughts/suggestions?
You're close. Just need to then call this:
$h.GetCrawlHistory() and parse it.
I've got my computer(Windows 7) hooked up to the TV, and i very often change output device for sound between Digital Audio (S/PDIF)(High definition audio device) and my headset (2- Corsair CA-HS1 USB Headset)
I wanna be able to execute a batch/script file who changes this for me so i don't have to "right click volume > playback devices > "Mark output device" and click "set default".
I know it's a luxury problem, but hey, maybe I can learn something from someone?
All help appreciated!
This is how I set 'Line 1' as the playback device:
start /min "" G:\......\nircmd.exe setdefaultsounddevice "Line 1"
NirCmd is a small command-line utility which you can download that allows you to do some useful tasks without displaying any user interface.
I had the exact same requirement as yourself, and AFTER stumbling across your posting I found the following:
https://web.archive.org/web/20131231034118/http://downloadsquad.switched.com/2010/06/16/windows-7-tip-how-to-change-the-default-audio-device-with-a-hot/
Unfortunately it's not a native Windows function; it requires the download of a small open-source scripting tool called AutoHotKey, but it works nicely and only requires a small amount of memory (1 ~ 2.5Mb)
The script provided in the original article doesn't work for me. It's searching for Enabled/Disabled devices and changing that value, as opposed to changing the default device.
I've edited it to switch between 2 default devices now.
It works by opening your Sound control panel (mmsys.cpl), then scrolling down the list of playback devices to the second item in the list (that's the {Down 2} part).
This is because my Speakers are the second item in my list.
It then checks to see if the device is default or not. If not, it sets it as the default and closes the window. If it's already the default, it scrolls down another 2 times and sets that as the default.
So, you'll need to ammend the {Down 2} lines to fit your own list of devices.
#+a::
Run, mmsys.cpl
WinWait,Sound
ControlSend,SysListView321,{Down 2}
ControlGet, selectedDevice, List, Focused, SysListView321
Loop, Parse, selectedDevice, %A_Tab%
if a_index <> 3
continue
else
{
if A_LoopField <> Default Device
{
ControlClick,&Set Default
ControlClick,OK
WinWaitClose
SoundPlay, *-1
return
}
else
{
ControlSend,SysListView321,{Down 2}
ControlClick,&Set Default
ControlClick,OK
WinWaitClose
SoundPlay, *-1
return
}
}
To follow up on Dale Newton's post, NirCmd is a great way to do this. On top of that if you pair it with AutoHotKey you can create an executable that will change your devices without opening pesky CMD windows every time you run it. For example, I have two sources that I switch between all the time, one is my headphones and they other is my monitor. For my monitor I created an ahk script that does this:
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir% ;I have nircmd in the same folder as these scripts
Run, nircmd setdefaultsounddevice "Acer X34-8" 1
Run, nircmd setdefaultsounddevice "Acer X34-8" 2
And another for my headphones with the last two lines changed to:
Run, nircmd setdefaultsounddevice "Headset Earphone" 1
Run, nircmd setdefaultsounddevice "Headset Earphone" 2
Afterwards you can compile each ahk script into an exe and bind each exe to a keyboard macro so you can execute them with a couple key presses. Personally I am using a Corsair K95 so I use their software to bind these to my 'G' keys.
Also to note, if you are in your sound preferences you can rename any of the devices to avoid naming conflicts.
I had a HDMI device that keeps changing it's name, so none of the existing solutions worked for me.
I eventually ended up with this powershell and use of the NirCmd app.
#File: TV.ps1
$name = "SMART*"
# list active audio playback devices. (Note for cature devices change Render to Capture)
$device = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Render\*\" | where {$_."DeviceState" -eq 1} | foreach-object -Process {(Get-ItemPropertyValue -Path ($_.PSPath + "\Properties\") -Name "{a45c254e-df1c-4efd-8020-67d146a850e0},2")} | Where-Object {$_ -like $name}
C:\bin\NIRCMDC setdefaultsounddevice $device 1
C:\bin\NIRCMDC setdefaultsounddevice $device 2
As far as I understand there is no way to do this programmatically. This is a deliberate design, since Microsoft does not want applications to override audio setting set by user.
You will find same answer here but if you solutions that manipulate windows you can have a look here.
The following script is written in Windows 7 and uses sendkeys. It is based on other snippets I found but adds to them to ensure selection is consistent and stray windows are not left displayed.
You may want to adjust SleepTime for your system if it still plays up.
Call the script using a shortcut with the index of the item you wish to select in the Playback Devices window as first parameter.
You can create a new 'toolbar' on your 'taskbar' to select each device with a single click:
Taskbar toolbar picture
'===============================================================================
'This script uses sendkeys to select the Sound Output device
'First parameter should be the desired device number in 'Playback Devices' list
'===============================================================================
Option Explicit
Const SleepTime = 200
Dim WindSh
'===============================================================================
'MAIN ROTUINE
'===============================================================================
'Check the command line input
if ( Wscript.Arguments.Count <> 1) then
MsgBox "You must provide a single integer argument representing the device number", vbinformation + vbokonly, Wscript.ScriptName
Wscript.Quit 1
elseif ( false = IsNumeric( Wscript.Arguments.Item(0) ) ) then
MsgBox "The argument provided was not an integer number: " & Wscript.Arguments.Item(0), vbinformation + vbokonly, Wscript.ScriptName
Wscript.Quit 2
End If
set WindSh = CreateObject("Wscript.Shell")
WindSh.run("control.exe mmsys.cpl")
do while (WindSh.AppActivate("Sound") = false)
WScript.Sleep SleepTime
loop
WindSh.sendkeys("{DOWN " & Clng( Wscript.Arguments.Item(0) ) & "}")
WScript.Sleep SleepTime
WindSh.sendkeys("{TAB 2}")
WScript.Sleep SleepTime
WindSh.sendkeys("{ENTER}")
WScript.Sleep SleepTime
WindSh.sendkeys("%{F4}")
WScript.Sleep SleepTime
if (WindSh.AppActivate("Sound") = true) then
WindSh.sendkeys("%{F4}")
end if
Might not be related to switching the audio device around via script, but I also have my computer hooked up to my TV via HDMI.
When I want to watch video files on the TV I use Media Player Classic Home Cinema - this lets me specify the audio device for MPH:HC in the options without switching over my default sound device on the entire computer.
If your usage is similar to mine maybe MPC:HC will solve your problem for you.
Note that if you use nircmd setdefaultsounddevice speakers in an enterprise or educational environment login script, the sound will still come out from the speakers when headphones are plugged in.