locked
Different -notmatch operator results in windows 10 1703, 1607 with Powershell 5 RRS feed

  • Question

  • Hi all, hopefully someone can point me in the right direction as this is driving me loopy...

    I'm checking if my various scripts are compatible with Windows 10 1703. They work as intended in Windows 7 and Windows 10 1607, but with 1703 the operator behaviour is different.

    This is the script I'm running on each of the systems:

    $PSVersionTable.PSVersion
    [environment]::OSVersion.Version
    $userProfiles = (get-ChildItem c:\users).name
    write-host "`nUser profiles on this system: $userProfiles "

    $userPNMatch = (get-ChildItem c:\users).name -notmatch "Administrator|Public|service|.1|default"
    write-host "`nUser profiles on this system with -notmatch operator: $UserPNMatch"

    Output for Windows 7

    Major  Minor  Build  Revision
    -----  -----  -----  --------
    5      1      14409  1012    
    6      1      7601   65536   

    User profiles on this system: Administrator masked.user1 appdata masked.user2 philip.allen philip.allen.1 Public service-cmna service-codesigning 

    User profiles on this system with -notmatch operator: masked.user1 appdata masked.user2 philip.allen

    Output for Windows 10 1607

    PS C:\temp> .\get-userprofiles.ps1

    Major  Minor  Build  Revision
    -----  -----  -----  --------
    5      1      14393  1358    
    10     0      14393  0       

    User profiles on this system: Default.migrated Phil Public 

    User profiles on this system with -notmatch operator: Phil

    Output for Windows 10 1703

    PS C:\temp> .\get-userprofiles.ps1

    Major  Minor  Build  Revision
    -----  -----  -----  --------
    5      1      15063  483     
    10     0      15063  0       

    User profiles on this system: Administrator philip.allen.1 Public w10user 

    User profiles on this system with -notmatch operator: 

    I'd like to be able to populate a variable using the -notmatch operator and then pipe contents to foreach, whats going on here?

    • Moved by Bill_Stewart Wednesday, September 13, 2017 9:15 PM This is not "fix/debug/rewrite my script for me" forum
    Thursday, July 27, 2017 1:15 AM

Answers

  • Thanks for your reply. I tested this out on two more w10 1703 machines. A machine that was built via inplace upgrade operates correctly, however a machine freshly built complete with windows updates yields same results.
    • Marked as answer by Cheezoid Monday, November 20, 2017 11:50 PM
    Thursday, July 27, 2017 6:38 AM

All replies

  • I have W10Pro 1703 and cannot reproduce your results:

    PS D:\scripts> notepad get-userprofiles.ps1
    PS D:\scripts> .\get-userprofiles.ps1
    
    Major  Minor  Build  Revision
    -----  -----  -----  --------
    5      1      15063  483
    10     0      15063  0
    
    User profiles on this system: Default.migrated DefaultAppPool jjonesLocalTest MSSQL$SQLEXPRESS MSSQLFDLauncher$S
    QLEXPRESS MSSQLLaunchpad$SQLEXPRESS MySite1 Public RDV GRAPHICS SERVICE ReportServer$SQLEXPRESS SQLTELEMETRY$SQLEXPRESS
    TestAuth TestUser testuser4
    
    User profiles on this system with -notmatch operator: jjones LocalTest MSSQL$SQLEXPRESS MSSQLFDLauncher$SQLEXPRES
    S MSSQLLaunchpad$SQLEXPRESS ReportServer$SQLEXPRESS SQLTELEMETRY$SQLEXPRESS TestAuth TestUser testuser4
    


    \_(ツ)_/

    Thursday, July 27, 2017 1:34 AM
  • The variable is an array just as it should be:

    PS D:\scripts> $userPNMatch = (get-ChildItem c:\users).name -notmatch "Administrator|Public|service|.1|default"
    PS D:\scripts> $userPNMatch
    jjones
    LocalTest
    MSSQL$SQLEXPRESS
    MSSQLFDLauncher$SQLEXPRESS
    MSSQLLaunchpad$SQLEXPRESS
    ReportServer$SQLEXPRESS
    SQLTELEMETRY$SQLEXPRESS
    TestAuth
    TestUser
    testuser4
    PS D:\scripts>


    \_(ツ)_/

    Thursday, July 27, 2017 1:36 AM
  • Thanks for your reply. I tested this out on two more w10 1703 machines. A machine that was built via inplace upgrade operates correctly, however a machine freshly built complete with windows updates yields same results.
    • Marked as answer by Cheezoid Monday, November 20, 2017 11:50 PM
    Thursday, July 27, 2017 6:38 AM