locked
PowerShell Profile problems RRS feed

  • Question

  • Hi

    I had a PowerShell profile that worked fine with Windows 7 (PS v3):

    #CSOM first
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client") | Out-Null
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime") | Out-Null
    
    $LogCommandHealthEvent = $true
    $LogCommandLifeCycleEvent = $true
    
    Set-Alias rc Edit-PowershellProfile
    
    function Prompt
    {
        $mywd = (Get-Location).Path
        $mywd = $mywd.Replace( $HOME, '~' )
        Write-Host "PS " -NoNewline -ForegroundColor DarkGreen
        Write-Host ("" + $mywd + ">") -NoNewline -ForegroundColor Green
        return " "
    }
    
    function Edit-PowershellProfile
    {
        notepad $Profile
    }
    
    #Import-Module SkypeOnlineConnector


    Moving to Windows 10 (PS v5.1),  I find that same profile is not being read/interpreted - even if I directly invoke it.

    In what way do I need to change the profile document - if at all?

    How do I make sure it gets executed?

    Thanks in advance

    QW

    • Edited by QWells_695 Thursday, April 11, 2019 8:49 AM Unintended duplication
    Thursday, April 11, 2019 8:47 AM

All replies

  • Type the following:

    "notepad $profile"

    Is the profile displayed correct?

    What is your execution policy setting?

    There is nothing in the code that would prevent it from running.


    \_(ツ)_/


    • Edited by jrv Thursday, April 11, 2019 9:00 AM
    Thursday, April 11, 2019 8:59 AM
  • Hi jrv

    Thanks for your response.

    The profile file is displayed in Notepad OK.

    PS C:\windows\system32> notepad $profile

    PS C:\windows\system32> Get-ExecutionPolicy
    RemoteSigned

    PS C:\windows\system32> 

    In addition, when I restart my ISE, I see the following:

    File \\<remote server>\emea\UK\F6\Folders\*****\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1 cannot be loaded. The file \\<remote server>\emea\UK\F6\Folders\*****\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1 is not digitally signed. You cannot run this script on the current system. For more information about running scripts and setting execution policy, see about_Execution_Policies at https:
    /go.microsoft.com/fwlink/?LinkID=135170.
    At line:0 char:0
    PS C:\Users\*****\WindowsPowerShell> $profile
    \\<remote server>\emea\UK\F6\Folders\*****\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1

    PS C:\Users\*****\WindowsPowerShell> 

    QW



    • Edited by QWells_695 Thursday, April 11, 2019 5:42 PM Extra info
    Thursday, April 11, 2019 5:22 PM
  • The code in your profile is not correct and won't likely work.  Much of the code will run with no error but it will not change anything.

    Try this to see what is happening.

    Get-Variable  LogCommandHealthEvent,LogCommandLifeCycleEvent


    \_(ツ)_/

    Thursday, April 11, 2019 5:27 PM
  • It looks like your "$Profile" variable is set to use a file share. That would make your profile "remote" and that requires a digital signature if your execution policy is set to RemoteSigned. The error you posted is pretty explicit about that: ". . . is not digitally signed."

    You could also try launching Powershell like this:

    powershell -executionpolicy bypass


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    Thursday, April 11, 2019 6:42 PM
  • If the share is in a trusted environment (domain) then signing is not necessary.  Also the profile worked before W10.

    I appears that W10 is not trusting the domain correctly.

    I run 5-1 on Windows 7 and W10 in a domain with the profile on a share and have never had an issue.

    I would suggest rejoining the PC to the domain to see if that clears the issue.  There area also issues with W10 when accessing shares after the patches before 1806.  That was fixed in 1806 but the enterprise channel may not have gotten the newest update due to not being in the "targeted" channel.  I am pretty sure the patch for this can be downloaded without needing the full update.  Contact MS support to get the patch if that appears to be the issue.

    Moving the profile local would test to see if this is the issue. 

    This can happen in a domain if the "Documents" folder is redirected via a GPO.


    \_(ツ)_/

    Thursday, April 11, 2019 6:55 PM
  • Oh - another clue is that running the profile from the prompt did not cause an error according to the OP's first post.  If it has always caused an error then the issue is likely the missing patch.


    \_(ツ)_/

    Thursday, April 11, 2019 6:58 PM
  • One other thing … if these are workgroups systems then be sure they are all in the same workgroup. I don't see why anyone would remote a Documents folder in a workgroup but it can be done.


    \_(ツ)_/

    Thursday, April 11, 2019 7:01 PM
  • It looks like your "$Profile" variable is set to use a file share. That would make your profile "remote" and that requires a digital signature if your execution policy is set to RemoteSigned. The error you posted is pretty explicit about that: ". . . is not digitally signed."

    You could also try launching Powershell like this:

    powershell -executionpolicy bypass


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    Yes - I was heading there but needed to see other things but … we are there now I guess.


    \_(ツ)_/

    Thursday, April 11, 2019 7:02 PM
  • I think you misread that:

    "I find that same profile is not being read/interpreted - even if I directly invoke it."


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    Thursday, April 11, 2019 7:25 PM
  • I think you misread that:

    "I find that same profile is not being read/interpreted - even if I directly invoke it."


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    Yes but the implication is that there was no error or at least that was how I read it.  Why would anyone fail to post the error for a problem.  Usually users post too many errors and never read more that the fist line of the first error.


    \_(ツ)_/

    Thursday, April 11, 2019 7:38 PM
  • Why?

    ¯\_(°_o)_/¯

    Who knows?


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    Friday, April 12, 2019 2:04 AM
  • Why?

    ¯\_(°_o)_/¯

    Who knows?


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)


    The Shadow knows …. ha ha ah ha ha ha!

    \_(ツ)_/

    Friday, April 12, 2019 2:12 AM
  • Hi jrv

    What does this do?

    I get:

    PS C:\windows\system32> Get-Variable logcommandhealthevent,logcommandlifecycleevent
    Get-Variable : Cannot find a variable with the name 'logcommandhealthevent'.
    At line:1 char:1
    + Get-Variable logcommandhealthevent,logcommandlifecycleevent
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (logcommandhealthevent:String) [Get-Variable], ItemNotFoundException
        + FullyQualifiedErrorId : VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand
     
    Get-Variable : Cannot find a variable with the name 'logcommandlifecycleevent'.
    At line:1 char:1
    + Get-Variable logcommandhealthevent,logcommandlifecycleevent
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (logcommandlifecycleevent:String) [Get-Variable], ItemNotFoundException
        + FullyQualifiedErrorId : VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand

    Friday, April 12, 2019 5:04 PM
  • Hi Rich

    The problem here is that my Win10 laptop (Edition: W10 Enterprise; Version: 1709; OS Build: 16299.1029) was given to me with 'Folder Redirection' configured, hence the error.

    This is because my PowerShell folder was in my Documents folder.

    In order for 'RemoteSigned' to work as before, I have copied my folder outside of Documents and thus out of scope of the folder redirection, but I can't work out how to tell PowerShell that my profile document has moved.

    QW

    PS  In writing this reply, I realised the old folder was still there, so I have renamed it with '.old' on the end.
    • Edited by QWells_695 Friday, April 12, 2019 5:12 PM extra info
    Friday, April 12, 2019 5:10 PM
  • Hi jrv

    What does this do?

    I get:

    PS C:\windows\system32> Get-Variable logcommandhealthevent,logcommandlifecycleevent
    Get-Variable : Cannot find a variable with the name 'logcommandhealthevent'.
    At line:1 char:1
    + Get-Variable logcommandhealthevent,logcommandlifecycleevent
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (logcommandhealthevent:String) [Get-Variable], ItemNotFoundException
        + FullyQualifiedErrorId : VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand
     
    Get-Variable : Cannot find a variable with the name 'logcommandlifecycleevent'.
    At line:1 char:1
    + Get-Variable logcommandhealthevent,logcommandlifecycleevent
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (logcommandlifecycleevent:String) [Get-Variable], ItemNotFoundException
        + FullyQualifiedErrorId : VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand

    Tells me if the profile has been executed.  It clearly is being rejected for security reasons.


    \_(ツ)_/

    Friday, April 12, 2019 6:01 PM
  • The issue has to be the join to the domain or the missing patch.  Fix that and the issue will cease.

    \_(ツ)_/

    Friday, April 12, 2019 6:03 PM
  • You can try changing the registry (HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders). See this URL for more info:

    https://stackoverflow.com/questions/5095509/is-it-possible-to-change-the-default-value-of-profile-to-a-new-value

    Alternatives are to create a "junction" (a.k.a. "symbolic link") or to modify the profile in  "C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1" and "dot-source" your profile from there (also mentioned in the URL above).

    You might also pursue your IT group for an update from 1709 (it's about 18 months old) and a current set of patches.


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    Friday, April 12, 2019 6:44 PM
  • You can try changing the registry (HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders). See this URL for more info:

    https://stackoverflow.com/questions/5095509/is-it-possible-to-change-the-default-value-of-profile-to-a-new-value

    Alternatives are to create a "junction" (a.k.a. "symbolic link") or to modify the profile in  "C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1" and "dot-source" your profile from there (also mentioned in the URL above).

    You might also pursue your IT group for an update from 1709 (it's about 18 months old) and a current set of patches.


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    All good possibilities but all also have gotchas associated.

    I recommend against changing the shell folders as they are system wide and can have really weird impacts on other programs.

    The best move would be to contact MS support and get the stand alone patch that fixes this issue.


    \_(ツ)_/


    • Edited by jrv Friday, April 12, 2019 6:49 PM
    Friday, April 12, 2019 6:47 PM
  • A better recommendation than what I suggested previously, is to sign your scripts (including your profile). You can either get your IT folks to create a code-signing certificate or, if you're only dealing with your own scripts and trust isn't an issue, you can use a self-signed cert. The self-signed process is described here (and it isn't difficult):

    https://community.spiceworks.com/how_to/153255-windows-10-signing-a-powershell-script-with-a-self-signed-certificate


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    Friday, April 12, 2019 9:10 PM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Monday, April 15, 2019 7:24 AM