Count property

Its frequently said that PowerShell is so big that no one can know everything about it.  I proved that today when I “discovered” a change in PowerShell of which I wasn’t aware.

 

If you create an array:

£> $a = 1,2,3

You can then get the number of members of that array i.e. its length

 

£> $a.count
3

 

£> $a[0]
1

 

In PowerShell 1.0 and 2.0 if you tried that on a variable that only held a single value you would get an error when you tried to access the first value:

£> $b = 1


£> $b.count

The count property returns nothing

 

£> $b[0]
Unable to index into an object of type System.Int32.
At line:1 char:4
+ $b[ <<<< 0]
    + CategoryInfo          : InvalidOperation: (0:Int32) [], RuntimeException
    + FullyQualifiedErrorId : CannotIndex

 

This changed in PowerShell 3.0 and later

£> $b = 1
£> $b.count
1


£> $b[0]
1

 

You can even try other indices
£> $b[1]
£>

 

And just get nothing back rather than an error.

 

This is really useful as you can now safely test on the Count property and if the value is greater than 1 to determine if its a collection.  Alternatively always treat it as a collection and iterate over the number of elements.  I can see this simplifying things for me in quite a few situations

Split-Path serendipity

I’ve used Split-Path and its associated cmdlet Join-Path a lot when working with file system paths. Something I read today started me asking if it would work with URLs

 

It does:

 

£> Split-Path -Path ‘http://powershell.org/wp/forums/forum/windows-powershell-qa/’ -Leaf
windows-powershell-qa


£> Split-Path -Path ‘http://powershell.org/wp/forums/forum/windows-powershell-qa/’ -Parent
http:\powershell.orgwpforumsforum

 

£> Split-Path -Path ‘http://powershell.org/wp/forums/forum/windows-powershell-qa/’ -NoQualifier
//powershell.org/wp/forums/forum/windows-powershell-qa/


£> Split-Path -Path ‘http://powershell.org/wp/forums/forum/windows-powershell-qa/’ -Qualifier
http:

 

The –Resolve parameter won’t work because its not a file system path but if you need to play with URLs then could be useful.

 

Just for completeness Join-Path won’t work with URLs because its attempting to resolve the file path

IE User Agent String in Windows Phone 8.1 Developer Preview

I think Microsoft is seriously worried about Windows Phone being not considered as a mainstream device as many websites are still not detecting (or interested in) it and thus rendering only the desktop version of the websites for IE on Windows Phone. But, if you have been noticing lately, Internet Explorer on Windows Phone 8.1 Dev Preview of GDR1/Update1 appears to have addressed this problem via a quirky trick. The user-agent (UA) string of IE on this update has changed to an interesting one; the new UA includes identifiers for Android and iOS devices too and so device-aware sites render properly as if they would on an iOS device or Android one depending the browser detection logic used by those sites. From my Lumia 1520 running WP 8.1 GDR1 DP, the UA looks like this:

Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 1520) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537

But at the same time the new UA causes some interesting problems too. An example is below, as recognized by a popular browser detection website:



For instance, if a website has mobile platform specific UI rendering logic (say, one that renders pages for native UX, visual cues, etc.), the new UA could cause confusion and make the browser detection logic become even more complex. Not only that, it could also skew the web analytics aspects of websites by accounting Windows Phone as either iOS or Android unless the analytics engines takes care of the new UA. So, if someone heavily relies on user-agent any important logic, be prepared to tweak your logic.

Spybot Search & Destroy Weekly Update – August 20, 2014

2014-08-20

Adware
+ Firseria + InstallMonetizer
Keyloggers
++ Win32.KeyLogger.ln
PUPS
+ OutBrowse ++ VaccineCore ++ Win32.MailPassViewer
Trojans
++ Win32.Kolab.blrt ++ Win32.Ramnit.A
Total: 2599824 fingerprints in 809788 rules for 7308 products

»www.safer-networking.org/about/updates/

Keyboard language..

I’m an ex-pat Brit living in Canada, and there is a very good chance that my first language will be English. Canada uses English UK spelling for many words, so the obvious choice for a keyboard language is English (Canada), and if I go to keyboard settings, English (Canada) is the ONLY language in the list.

ST1The Notification Area tells another story. If I click on the ‘ENG’, I get a choice of TWO languages, and traditionally, the ENG has only exited if there was a choice of more than one language in the list. As I have already explained, I don’t have two in my list, but I can get rid of the ENG by adding English US to the list and then removing it.  This works for the session, but appears on a reboot..

Aha, this is Windows 8.1, and the language bar isn’t a toolbar anymore, and neither is it a Notification Area icon, so there has to be something else putting it there, and here it is..

ST2It is now a ‘system’ icon, and at the base of the Notification Area properties window, in suitably small print, is where you get to turn it off. See the top line in the graphic?

The language toolbar has joined the ranks of the clock, volume and network icons, probably should always have been in that group, but it wasn’t and I have wasted an hour in the last two days trying to see it off. Even little changes like this can turn into a real annoyance, and as far as I am aware, this blog post is the only location on the Internet where you can find out that the Windows 8.1 language ‘bar’ is not a bar at all..

Smile

How to Enable or Disable Automatic Updates in Windows Media Player

Windows Media Player (WMP) is updated from time to time with new features and performance enhancements. You can let the Player check for updates automatically or you can check for updates manually.

This tutorial will show you how to enable or disable Windows Media Player from automatically checking for updates periodically and the “Automatic updates” options for all users.

Read more…

Set how Often Windows Media Player Automatically Checks for Updates

Windows Media Player (WMP) is updated from time to time with new features and performance enhancements. You can let the Player check for updates automatically or you can check for updates manually.

This tutorial will show you how to change how often Windows Media Player automatically checks for updates in only your user account in Windows.

Read more…

Windows Media Player (WMP) is updated from time to time with new features and performance enhancements. You can let the Player check for updates automatically or you can check for updates manually.

This tutorial will show you how to manually check for updates in Windows Media Player.

Read more…

Targeted Attacks – Seven resources to check for new attacks

By harrywaldron Trend Labs shares techniques for spotting targeted attacks, which are highly specific and designed to blend into corporate email or other resource functions in a highly legitimate manner.

http://blog.trendmicro.com/trendlabs-security-intelligence/7-places-to-check-for-signs-of-a-targeted-attack-in-your-network/

http://about-threats.trendmicro.com/us/threat-intelligence/targeted-attacks/

QUOTE: Targeted attacks are designed to circumvent existing policies and solutions within the target network, thus making their detection a big challenge. As we’ve stressed in our previous entry about common misconceptions about targeted attacks, there is no one-size-fits-all solution against it; enterprises need to arm themselves with protection that can provide sensors where needed, as well as IT personnel equipped enough to recognize anomalies within the network and to act accordingly.

1. Check for Injected DNS Records
2. Audit Accounts for Failed/Irregular Logins
3. Review Security Warning messages and logs
4. Check for Strange Large Files
5. Audit Network Log for Abnormal Connections
6. Abnormal Protocols
7. Increased Email Activity and Spikes

Security – Built on foundation of Trust

By harrywaldron As McAfee security shares, “Trust Is the Most Valuable Asset” in protecting information resources

http://blogs.mcafee.com/mcafee-labs/trust-valuable-asset

QUOTE: Traditionally, providing security has been primarily a task of the state, but who should be responsible for safeguarding cyberspace? Who will build trust in it? Most of digital infrastructure is owned and operated by the private sector. Moreover, the majority of actors operating in the field of cybersecurity are private. The state has unique capabilities to provide security and maintain trust among people, for example, by mobilizing its unique resources and by passing and enforcing laws.

Trust is an important ingredient of security. Doubt leads to insecurity, whereas trust builds security. When there is no certainty, people seek additional security measures. In cyberspace, these measures usually refer to technical solutions to particular problems. In other words, security is produced through technology. However, addressing the question of trust this way is only part of the solution. Regulation—standards, laws, treaties, and good practices—that establishes rules of the game for cyberspace is also important. Yet the biggest challenge remains in people’s unawareness and lack of familiarity with digital technology.


It is the shared responsibility of all online actors to reinforce trust in the digital world. Thus it lies on everyone’s shoulders to strengthen cybersecurity. The state does its part by establishing national and international regulation and administrative structures needed for cooperation. It strengthens public-private partnerships and allocates powers both upward and downward to different actors. It strives to normalize people’s relationship to cyberspace and educates them to become smart e-citizens, shares information, provides services online, and counteracts threats in the digital world. It also uses market mechanisms, for example, purchasing power and the creation of incentives for companies, other organizations, and individuals to invest in cybersecurity

Recent Comments

Archives