I have been running PowerShell v3 for some time on several different systems. On occasion I wish to check compatibility or other issues with v2 so I switch to v2 within an existing PowerShell with this:
PS> powershell -version 2
As a matter of course I then use either $hosts.Version or $PSVersionTable to do a sanity check. But on one machine when I did this they both reported I was still in a V3 shell. I tried again from scratch; same result. I also tried invoking it from a DOS shell instead of a PowerShell; again, same result. Then to check my own sanity(!) I went to another system, did the same sequence, and it worked as expected--I did indeed switch from a V3 to a V2 environment.
The only other observation I have is that on the system that worked, I got a 2009 copyright notice when it started up the inner shell; on the system that did not it showed 2012.
Final detail: of the two machines mentioned, it worked on Win8 and failed on Win7 enterprise but I really doubt that is a relevant factor here.
I would be really surprised if (a) this is a PS bug or (b) I am the only one seeing the issue, yet web searching has been fruitless for me thusfar. Any thoughts on why this might be happening?
One reason would be that .NET 2.0 is not installed on the failing system, I cant recall if it had to be already installed prior to v3 or you can install it after upgrading to v3.
Quick search turned up this, just an idea? Maybe V2 is not installed?
Is Version 2 installed?
Related
New to Pester, installed Powershell and Pester on Ubuntu 16.04 per instructions on the Pester Github page https://github.com/pester/Pester. Executed their sample scripts Get-Planet.Tests.ps1 and Get-Planet.ps1 and it worked as advertised. Tried the same thing on Windows 10 following their instructions, and got "-Be is not a valid Should operator".
Not sure where to look for the problem, as I'm new to Pester and to Powershell as well. It's their own sample, installed per their instructions, with no modifications. Any help will be appreciated.
To expand on the other answer, Windows 10 (and Server 2016) come with Pester version 3.4.0 pre-installed. From version 4 of Pester onward some Pester syntax was changed, including the Should assertions which are now provided as parameters (e.g Should Be became Should -Be).
The documentation reflects the newer syntax, hence why it is misleading for older versions of Pester.
You can install the latest version of Pester on your Windows 10 machine, by running the following with an admin-level PowerShell window:
Install-Module -Name Pester -Force -SkipPublisherCheck
To see what else changed between Pester versions 3 and 4, see here:
https://github.com/pester/Pester/wiki/Migrating-from-Pester-3-to-Pester-4
The problem turned out to be the wrong version of Pester on the Windows 10 system, as suggested by user2864740.
I have been using some powershell scripts to query active directory users and its very useful
Recently the script stops working even though I have not changed it !
I don't understand why. The prereqs etc. have not been altered
The errors im getting include:
"import-module: a local error has occurred .... { import-module $_ }...
Error initializing default drive: 'a call to SSPI failed see inner exception...
I am using windows 8 64 bit had all the pre reqs sorted e.g. RSAT tools, powershell option enabled. Dot net 4.5 etc. have enabled RSAT through add remove programs.
I have tested the same script on another windows 7 machine and it works fine which makes it look like there is something awry on the windows 8 machine. I have googled about but haven't found a working solution.
Ive checked to see if id unchecked anything that would upset powershell but don't see anything. Ive recreated my windows profile, I have reinstalled the RSAT tools for windows 8.1 64 bit. Ive re domained the machine.
The active directory scripts were running fine then suddenly stopped. I haven't Installed any software recently. I'm a domain admin and can use active directory with the gui with no problems. I'm at a loss.
Wondering if anyone knows what could have upset powershell on the windows 8 system or see anything ive overlooked
Thanks for reading
Confuseis
As some of you have seen, I'm a newbie with Chef, and there seems just so much to learn that it's hurting my head :(...
One of the things I ran into earlier testing was that some example recipes I found would fail because I am using Win2K8 as the NODE and that has Powershell V2 rather than Powershell V3.
So, as a kind of learning exercise, I would like to try to make a Chef cookbook to deploy PS V3 to Win2K8 R2. I think that I'll also need to get .NET Framework 4.5.x in order to install the PS V3 .msu (Windows6.1-KB2506143-x64.msu).
So, how do I make such a cookbook?
i've been looking around and found a dotnetframework cookbook and I've added that to my WORKSTATION.
I've also found this:
http://thinkofdata.blogspot.com/2014/07/installing-microsoft-net-framework.html
which seems like a different approach than using the dotnetframework cookbook?
I guess I'm confused about all of this? Are both of these approaches (using the dotnetframework cookbook vs. the one from the link above) "ok"?
Also, if I want to do the former, how do I actually do that? What do I need to put into my recipes/default.rb?
Finally, for now at least, what about executing the .msu after that, to do the PS V3 upgrade? How do I do that?
Sorry for all the questions (and hopefully I won't get flamed too much for them). I'll continue to bang away but hopefully you all can help point the way!
Thanks in advance,
Jim
You could use the windows_package command to be able to do this slightly differently (and not have to rely on a file download to determine whether or not something was installed on a box), but then you would have a dependency on the windows cookbook. This will work after downloading the Chef Development Kit and just using:
chef-apply install_powershell_4_0.rb
This also installs powershell 4.0 via the Windows Management Framework 4.0 installer rather than powershell 3.0 (which is why .NET framework 4.5 needs to be installed prior to installing WMF 4.0 because otherwise powershell isn't updated and stays at 2.0).
The server will reboot 3 times between each install, so you will have to run the chef-apply command to continue (or actually install chef client).
Here is the install_powershell_4_0.rb file:
#Create installs directory to house downloads
directory 'c:/installs' do
end
#Install Windows 7 and Windows Server 2008 R2 Service Pack 1 (KB976932)
remote_file "c:/installs/windows6.1-KB976932-X64.exe" do
source "http://download.microsoft.com/download/0/A/F/0AFB5316-3062-494A-AB78-7FB0D4461357/windows6.1-KB976932-X64.exe"
end
execute "c:/installs/windows6.1-KB976932-X64.exe /quiet" do
action :nothing
subscribes :run, resources(:remote_file => "c:/installs/windows6.1-KB976932-X64.exe")
end
#Install .NET 4.5
remote_file "c:/installs/dotNetFx45_Full_setup.exe" do
source "http://download.microsoft.com/download/B/A/4/BA4A7E71-2906-4B2D-A0E1-80CF16844F5F/dotNetFx45_Full_setup.exe"
end
execute "c:/installs/dotNetFx45_Full_setup.exe /quiet" do
action :nothing
subscribes :run, resources(:remote_file => "c:/installs/dotNetFx45_Full_setup.exe")
end
#Install Windows Management Framework 4.0
remote_file "c:/installs/Windows6.1-KB2819745-x64-MultiPkg.msu" do
source "http://download.microsoft.com/download/3/D/6/3D61D262-8549-4769-A660-230B67E15B25/Windows6.1-KB2819745-x64-MultiPkg.msu"
end
execute "c:/installs/Windows6.1-KB2819745-x64-MultiPkg.msu /quiet" do
action :nothing
subscribes :run, resources(:remote_file => "c:/installs/Windows6.1-KB2819745-x64-MultiPkg.msu")
end
You then should be able to open a powershell command prompt and see 4.0 as the PSVersion via running:
$psversiontable
I will try this again. I can only get my .exe to run on the computer which created it and select other ones. Even once a application has been built into an .exe is it necessary that the computer it is run on still has powershell studio? Right now the executable will only run on computers with powershell studio, I am not sure if it is because these other computers are lacking a library or something along those lines or if every computer that I want to run it needs powershell studio. This as I have asked around is actually an issue with other executables which have been made from powershell studio so the problem is not exclusive to my code, which if necessary I can show some of. However I think it is more of an issue with the settings in the .exe builder which is something I am very new to and do not fully understand what or if I need to get it to work properly.I currently have left all the settings in the builder as the default settings so I am sure it is something in there that needs to be looked at I am just at a loss as for what.
Not a problem, just recompile it targeting the lowest common denominator. If you are on Powershell v3, but have some clients on v2, you'll need to recompile targeting v2.
To recompile, go into Sapien Studio and look for the drop down box on the ribbon, it probably says v3 - 64bit, change that to v2 -64bit and recompile. Good luck.
Alternatively you could install powershell v3 on those other machines and not need to recompile. That would also be the answer if you have to use a v3 cmdlet that simply does not exist in v2.
Noted: Future readers may also run into issues with x86/x64 bitness and system32 folder, if you are getting redirected into syswow64 sandbox, recompile 2 versions, one for 32bit, one for 64.
Do PowerShell scripts run under Mono?
I would like to run them on a Mac.
There is an open source version of PowerShell called Pash designed for Mono. It is not complete, but may be able to do what you need:
http://pash.sourceforge.net/ (this project has not been active for quite some time)
Checkout the re-start at: Pash-Project on GitHub.
Powershell has now been open-sourced and is available here.
As of right now it is V6.0 alpha. I've been running it on OS X for a lot of file operations and it has been working very well.
Note that you may need to install .Net Core to get Powershell to behave properly. Also note that system.management.automation.runspaces works right out of the box (for runspacepools).
The powershell.exe stub is actually a native win32 program, not a managed assembly. It may be possible in the future to host the System.Management.Automation assembly in Mono, but I'm fairly sure it doesn't work at the moment.