{"id":2165,"date":"2017-04-04T19:56:26","date_gmt":"2017-04-05T00:56:26","guid":{"rendered":"http:\/\/www.wiredprairie.us\/blog\/?p=2165"},"modified":"2017-04-05T07:09:38","modified_gmt":"2017-04-05T12:09:38","slug":"automatic-reconnecting-iscsi-drives-in-windows-10-using-powershell","status":"publish","type":"post","link":"https:\/\/www.wiredprairie.us\/blog\/index.php\/archives\/2165","title":{"rendered":"Automatic Reconnection of iSCSI Targets in Windows 10 using PowerShell"},"content":{"rendered":"

When my highly recommended Synology <\/a>Disk Station<\/strong> reboots for a required update (I’ve got it set to automatically reboot), a shared Windows 10 PC in our house cannot always successfully reconnect to the iSCSI targets without manual intervention. Unfortunately, I haven’t always noticed which has led to several features of Windows not functioning the way I want (I have mapped the iSCSI drives\/disks via Windows and made them into network shares for the other PCs\/laptops in our house — this way I can use Windows bitlocker encryption on the iSCSI drive contents).<\/p>\n

To make the connection more automatic, I created a simple one line PowerShell script that periodically attempts to connect to any disconnected iSCSI targets using the Windows Task Scheduler.<\/p>\n

I saved this into a script file called reconnect-iscsi-targets.ps1<\/strong>:<\/p>\n

Get-IscsiTarget | where ($_.isConnected -eq $false) | Connect-IscsiTarget<\/pre>\n

Then, in the Task Scheduler, I created a new task set to run every 10 minutes daily. The script just gets all iSCSI targets, filters only those that aren’t connected, and then passes the results to the connection cmdlet.<\/p>\n

For the action, I selected “Start a program”<\/strong> for program\/script, I entered: “powershell.exe”<\/strong>, and then added the arguments “-File<\/strong>” and the full path to the file name, like:<\/p>\n

-File c:\\Users\\aaron\\Documents\\reconnect-iscsi-targets.ps1<\/pre>\n

If there are spaces in the path to the PowerShell file, be sure to add quotes around the full path and file name.<\/p>\n

\"\"<\/p>\n

You shouldn’t need the start in<\/strong>\u00a0option set (leave it empty if you’d like).<\/p>\n

On the General tab of the task, make sure you’ve set the “Run whether user is logged on or not<\/strong>” option and “Run with highest privileges<\/strong>.”<\/p>\n

Next up — how to quickly create a Self-Signed Code-Signing<\/a> certificate. And, how to actually allow scripts to run!<\/p>\n","protected":false},"excerpt":{"rendered":"

When my highly recommended Synology Disk Station reboots for a required update (I’ve got it set to automatically reboot), a shared Windows 10 PC in our house cannot always successfully reconnect to the iSCSI targets without manual intervention. Unfortunately, I haven’t always noticed which has led to several features of Windows not functioning the way […]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[4,5,173],"tags":[174,175,176],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pd5QIe-yV","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":2170,"url":"https:\/\/www.wiredprairie.us\/blog\/index.php\/archives\/2170","url_meta":{"origin":2165,"position":0},"title":"How to sign Powershell scripts with self-signed certificates in Windows 10","date":"April 4, 2017","format":false,"excerpt":"I wanted to allow all signed Powershell scripts to run on a PC in our house on Windows 10. To do that, I needed a code-signing certificate. Unfortunately, the days of easily obtaining a free code signing certificate seem to have ended. Have no fear! You can create a self-signed\u2026","rel":"","context":"In "General"","img":{"alt_text":"Drag Certificate Into Trusted Root Certification Authorities","src":"https:\/\/i0.wp.com\/www.wiredprairie.us\/blog\/wp-content\/uploads\/2017\/04\/DragCertificateIntoTrusted-1.gif?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1773,"url":"https:\/\/www.wiredprairie.us\/blog\/index.php\/archives\/1773","url_meta":{"origin":2165,"position":1},"title":"AV Club \/ Our home setup 2012","date":"December 12, 2012","format":false,"excerpt":"I\u2019ve done a lot of reworking of our computers and network recently and thought I\u2019d post some details about the various physical and digital parts that make our humble WiredPrairie home work. Using Google Docs, I created a labeled diagram with most of the moving parts of our house (WOW,\u2026","rel":"","context":"In "Recommendations"","img":{"alt_text":"Home Setup","src":"https:\/\/i0.wp.com\/www.wiredprairie.us\/blog\/wp-content\/uploads\/2012\/12\/Home-Setup_thumb1.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":1222,"url":"https:\/\/www.wiredprairie.us\/blog\/index.php\/archives\/1222","url_meta":{"origin":2165,"position":2},"title":"Windows Home Server 2011 & “the server appears to be offline” when trying to connect to the LaunchPad","date":"August 10, 2011","format":false,"excerpt":"Within the past few days--maybe after a recent Windows Update--one of my laptops started to fail to successfully connect to the WHS 2011 server I\u2019ve got in my home. The error was \u201cthe server appears to be offline\u201d and asked if I\u2019d instead want to connect off-line. (Yeah, no thanks.)\u2026","rel":"","context":"In "Software"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.wiredprairie.us\/blog\/wp-content\/uploads\/2011\/08\/image2.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":1901,"url":"https:\/\/www.wiredprairie.us\/blog\/index.php\/archives\/1901","url_meta":{"origin":2165,"position":3},"title":"PRTG Network Monitor for Windows","date":"July 16, 2013","format":false,"excerpt":"My current router\/firewall\/VPN device has an unfortunately mediocre live monitor for bandwidth statistics, but supports SMNP. So after a reasonably painful search for decent free options (oh boy are there some awful ones!), I installed the freeware version of the Paessler PRTG monitor so that I could easily see the\u2026","rel":"","context":"In "General"","img":{"alt_text":"image","src":"https:\/\/i0.wp.com\/www.wiredprairie.us\/blog\/wp-content\/uploads\/2013\/07\/image_thumb3.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":1541,"url":"https:\/\/www.wiredprairie.us\/blog\/index.php\/archives\/1541","url_meta":{"origin":2165,"position":4},"title":"Adobe Lightroom and exporting to subfolders","date":"February 8, 2012","format":false,"excerpt":"For some reason, versions 1 \u2013 3 of Adobe Lightroom cannot export images in a way that mirrors the original structure of your photo library. I can\u2019t offer a reason why other than it was missed by the development and design teams. There\u2019s been enough interest in it apparently that\u2026","rel":"","context":"In "Photography"","img":{"alt_text":"image","src":"https:\/\/i0.wp.com\/www.wiredprairie.us\/blog\/wp-content\/uploads\/2012\/02\/image2.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":111,"url":"https:\/\/www.wiredprairie.us\/blog\/index.php\/archives\/111","url_meta":{"origin":2165,"position":5},"title":"Disabling Apple Software Update on Vista","date":"April 10, 2008","format":false,"excerpt":"I've complained (and so have many others) about the Apple Software Update functionality -- especially now that it suggests that I update software I never had installed (Safari)! On Vista (and XP is probably similar), there's a scheduled task that runs once a week to look for updates. To stop\u2026","rel":"","context":"In "Software"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.wiredprairie.us\/blog\/index.php\/wpjson\/wp\/v2\/posts\/2165"}],"collection":[{"href":"https:\/\/www.wiredprairie.us\/blog\/index.php\/wpjson\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wiredprairie.us\/blog\/index.php\/wpjson\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wiredprairie.us\/blog\/index.php\/wpjson\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wiredprairie.us\/blog\/index.php\/wpjson\/wp\/v2\/comments?post=2165"}],"version-history":[{"count":8,"href":"https:\/\/www.wiredprairie.us\/blog\/index.php\/wpjson\/wp\/v2\/posts\/2165\/revisions"}],"predecessor-version":[{"id":2187,"href":"https:\/\/www.wiredprairie.us\/blog\/index.php\/wpjson\/wp\/v2\/posts\/2165\/revisions\/2187"}],"wp:attachment":[{"href":"https:\/\/www.wiredprairie.us\/blog\/index.php\/wpjson\/wp\/v2\/media?parent=2165"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wiredprairie.us\/blog\/index.php\/wpjson\/wp\/v2\/categories?post=2165"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wiredprairie.us\/blog\/index.php\/wpjson\/wp\/v2\/tags?post=2165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}