We have one script server running Windows Server 2012 with PowerShell 4.0 and multiple other servers that run Windows Server 2008R2 with PowerShell 4.0.
What we're trying to do is use the function Get-FSRMQuota from the module FileServerResourceManager found on Server 2012 on the 2008R2 file servers. When in an RDP session on the 2008R2 file server, this can be easily done:
# From PowerShell on the file server:
New-PsSession $ScriptSever
Invoke-Command -Computer $ScriptSever {Import-Module FileServerResourceManager}
Invoke-Command -Computer $ScriptSever {Get-FSRMQuota}
However, all our scripts launch from the script server and are managed there. So we have a job that's initiated on the script server (2012) to run on the 2008R2 servers using PS Remoting. But from within this job it's not possible to import a module from the script server that initiated the job.
So my question, is there a way to import the module FileServerResourceManager from the script server into the remote session on the file server?
I hope I made it clear, as it's a bit difficult to explain. Thank you for your help.
It's not possible. According to https://technet.microsoft.com/en-us/library/jj900651(v=wps.620).aspx, FileServerResourceManager is only available as of Windows 2012.
Related
Working on a corporate laptop with no access to local admin but with the execution policy set to unrestricted, when trying to import the SQLPS cmdlets I receive an error indicating a problem with the path, shown below.
Why is the import-module command looking at my AppData\Local\Temp folder?
If a reinstall of SSMS does not do the trick, try installing the PowerShellTools.msi package of the SQL Server feature pack that corresponds with the latest server you will be working on.
SQL Server 2014
SQL Server 2016
I would also recommend running Get-Module Sqlps | Format-Table -Property ModuleType,Name,Path to check if there are multiple copies of the module and remove them as needed.
First off: This is not a duplicate of How to remote execute an ELEVATED remote script in PowerShell.
My scenario is similar but different in a certain way. What I want to do is the following:
Invoke-Command -UseSSL -ComputerName "$COMPUTER" -FilePath \\script.example.com\secretshare$\install_test.ps1 -ArgumentList 'U'
As the called script performs an installation and manipulates firewall rules, it needs elevated privileges. Irritatingly the error I get is an access error on the share mentioned above.
When I use this suggestion where I use PowerShell DSC, which is run as SYSTEM, it works. But only on Servers running Windows Management Framwork 4.0. So obviously I need a solution for Windows Server 2008 (R2) systems.
I hope someone can point me to the right direction so I can update this question to help other admins aswell.
In my environment I have a single server that has access to pretty much my entire network. That server is running Windows 2008 r2, and I have upgraded Powershell to version 4.0. The question I have is this... Can I run cmdlets from that machine on other machines that are version 4 specific?
For instance, when I am using Powershell, even though it is version 4, it doesn't give me an intellisense autocomplete for "Get-Volume" like it would on a 2012 r2 machine. I understand that it won't run on that machine because the infrastructure won't allow for it, but what about a 2012 r2 machine remotely?
I am looking to run batch scripts from there for various purposes.
First, this is probably a ServerFault-question as it's related to server-administration.
PowerShell 4.0 installed on 2008 R2 can't run 2012 cmdlets on a 2012 R2-machine like Get-Volume -ComputerName My2012Server, because the cmdlets doesn't exist on your 2008 R2 machine. However, you should be able to invoke the cmdlet on the 2012 R2-server, like:
Invoke-Command -ComputerName My2012Server -Scriptblock { Get-Volume }
Be aware that you would not get autocomplete support when writing it as the commands and help files aren't installed on your 2008 R2-server
Import-PSSession is also a possibility if your gonna run the commands interactively. For a script I would probably still use Invoke-Command.
Get-Volume in your example is available only on Windows Server 2012 and above. So, it won't auto-complete on a 2008 R2 system. You can use PowerShell implict remoting.
Using implict remoting, you can import all cmdlets from a remote system into a local session and use them as if they are available on the local system.
Ive never used powershell before but it seems like the correct tool to use to read the number and size of mailboxes on our 2007 and 2010 exchange servers. I'm running Powershell on Windows 7 and NOT on the exchange server. The commands used in the examples i have found are not recognised.
From my initial reading it appears i need the Exchange snap in. However, i can't seem to find a download page or instructions for loading it into Powershell, or if it is even possible to access this data from a workstation other than the exchange server. I was wondering if some one could give me some feedback on my problem and point me in the right direction.
thanks.
I have gotten this to work on windows 7 64 bit with exchange 2007 64
I installed the exchange management console via the exchange server 2007 installation files
you don't need to establish a remote powershell session, you run the commands with a domain/network administrator privileged powershell on the workstation.
I'm trying to get just the powershell snapin as I don't need the whole console, but as of right now, with the whole console and powershell you can load the exchange management snapin to powershell and create mail-enabled user accounts.
after installing the exchange management console you can execute
add-pssnapin microsoft.exchange.management.powershell.admin
to load the exchange snapin and begin pulling exchange data.
on top of that you may need to start the service on the exchange server "microsoft exchange system attendant"
i guess you need to establish a powershell remote session to the exchange server and run your powershell cmdlets.
You can start with having a look at the help about remote powershell
PS C:\Windows\system32> help about_Remote
Once you establish a remote powershell session to the exchange server you can add the Exchange Management Shell snap-in from Windows PowerShell
Click Start, click Programs, and then click Windows PowerShell 1.0, Click Windows PowerShell, Type the following command:
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin
Use the chdir command to change to the Exchange Server\Bin directory. For example, type:
chdir "c:\program files\microsoft\exchange server\bin"
Type the following command:
.\Exchange.ps1
Once the exchange module is loaded you can start using the various cmdlets.
I had the same problems when I was first trying to get this work, and it was never clear to me what I needed to do.
I was very new to Powershell and was trying to run the add-pssnapin without first creating a new session.
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://EXCHANGE-SERVERNAME/PowerShell/ -Authentication Kerberos -Credential $myCred
Import-PSSession $Session
Where the -ConnectionUri points to your exchange server name and the $myCred holds your admin credentials to access the server.
This will import all modules you can use against MS Exchange.
Note1: you can narrow this down to improve the speed of the import by only selecting to import certain modules you will be using. Good if, for example, you know you will only use certain tools.
You can do this by adding -CommandName and list necessary aliases you want to import.
Note2: Good practice to remove the sessions after you are finished:
Remove-PSSession $Session
This is incredibly difficult to do. I can't believe it. It should be so easy.
Anyway, using WMI (with both vbscript and perl) I'm able to start a process on a remote machine that runs a .exe, but I cannot get the output to write to a log. This is driving me nuts. I have to use WMI or powershell because I can't install anything additional on the remote machines, which are all Windows 2003 or newer. I also cannot assume that powershell remoting is enabled on all target machines, so I may not even be able to use powershell. This can cause a problem with powershell.
Here is what I'm trying to do in psuedo code:
servers = server1, server2, server3
for each server in servers
run command on remote server >> log.txt
next
I'm assuming you have powershell remoting enabled on all the servers and that you want the results saved in a local log file (ie not on each server)...
$Servers = "server1", "server2","server3"
Invoke-Command -ComputerName $Servers -ScriptBlock { ping.exe www.stackoverflow.com } >> c:\localfile.txt
This also assumes that your exe outputs to stdout, I think there will be issues capturing other streams.