Powershell command SCCM 2012 - Get all Resource Names from device collection? - powershell

I'm still learning about PowerShell and SCCM.
At the moment i'm trying to get all resource names of a device collection into an array variable. I don't know if this is possible?
Example:
Computers: Win7, Win8, CM02,....
into a variable like:
$computers = COMPUTERNAMEWIN7.local.domain.lo, COMPUTERNAMEWIN8.local.domain.lo, COMPUTERNAMECM02.local.domain.lo
This is what i'm trying to achieve:
I'm trying to deploy LibreOffice to all computers i have under my control in SCCM 2012.
So i have a Device Collection: "All Systems" with all these computers in it.
and then use aForeach-Object command to copy and install the .Msi file of LibreOffice.
Is there a PowerShell command to get these into an array like the example, when specifying the device collection name ?
thank you :)

Related

Get printers installed from server from remote computer using Powershell

I'm trying to write a script in powershell that will get all the installed printers in each computer.
At my organization we use a print server running win server 2019 to manage and share all the printers.
For some reason the commands
Get-Printer and win32_Printer return only the locally installed printers (which are the windows defaults like ms print to pdf).
I've tried to run the lines on the server itself and got the full list cause they are installed locally.
Is there a way the get a printer that was installed from a server? And in the future I will also want to install and uninstall those printers via powershell.
I have a function that does this, specifically, for our environment, but it relies on several other "self-coded" functions, so I'm not going to paste it here.
What you need to do is connect to the registry on the remote computer and interrogate it. The subkeys for HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Connections are GUIDs, and interrogating the PRINTER property of each of those subkeys will give you the UNC pathname of the connected printer.
This does NOT return the locally-defined printers; for that, you need Get-Printer.

Is it possible to delete or overwrite cmdlets?

I'm working with DNS resource records in Powershell 5 using code that I inherited from the guy who was trying to do this before me. The cmdlet I am trying to use is Add-DnsServerResourceRecordA.
Part of his code has import-module certain folder\PowerShell\Modules\DnsServer. The weird thing is, it seems like as I was trying bits and pieces of the code earlier, I was able to use the add-DNSblah cmdlet. Now, after It ried running the whole script including the import-module, Powershell is saying that the cmdlet does not exist natively, and when I import the module and run it it is giving me Add-DnsServerResourceRecordA: Invalid Class.
It is my understanding that Add-DnsServerResourceRecordA should be included in my normal Powershell 5.0. Could that Import-Module have permanently damaged PS somehow? Why else would the cmdlet not show up, even in a Get-Command "dns"?
I'm pretty sure you will need the Remote Server Administration Tools (RSAT) installed to have these cmdlets available on a non-server Windows OS.
You can download them from this page: https://www.microsoft.com/en-gb/download/details.aspx?id=45520.
Not really sure why the Import-Module does not fail if the DNSServer module is not present on the system.
If RSAT are already installed, you can try to reinstall them.

Query Active Directory via PowerShell script to get attributes for users in a csv file

I am new to the PowerShell. I have a csv file which has info about the login ids for a set of users. I need a PowerShell script that can take input from this csv file and query AD for custom attribute 5, last name and first name. Thank you all for your assistance.
Thanks,
Learn basic PowerShell. Ex. read PowerShell Tutorial for beginners. Chapter-menu on the right side, and skip the last ActiveDirectory part. You should rather use the official Active Directory module that's installed on DCs and available for servers and clients(install RSAT), or Quest ActiveRoles module.
Import data using Import-CSV.
Query AD using Active Directory module.. Get-ADUser.

List of Hyper-V Servers Remotely into CSV Format?

Im thinking this would be easy, but want to make sure it's possible.
Is there an easy way to grab a list of all Hyper-V Servers/VM's on a machine and maybe export it to a CSV File? (excel spreadsheet).
Get-VM returns quite a bit of information, but is there any way to split that? Maybe store them into an array?
This is my first time with powershell so Im mainly wanting to make sure this is a easily doable task.
Problem is.....the machine is a Windows 2008 Server R2 that doesn't support Hyper-V Modules I believe (I think only Win 8 does).....so I've been remoting into it....so can I use Powershell to Remote into it and Run this script?
I tried doing a Get-VM from command line using Invoke-Command, but it complains about File-Path....but I was just trying to do a Get-VM from command line.
Sounds to me like you need to take some smaller steps first. In this case, I would avoid PowerShell remoting. If you have the modules installed and and loaded in your PowerShell session you should be able to point to a remote host to run Get-VM without having to do anything crazy.
As for filtering output for a CSV, You should use Select (to select certain properties of the object and ignore others) and Where-Object (to filter what objects are displayed, based on properties of the object.
Get-VM -ComputerName HyperVHost.constoso.local | Where-Object {$_.OS -match "2008"} | Select Name, Host | ExportTo-CSV C:\csv.csv
The above example was fictional, but it's the syntax I would use to filter input before putting it into a CSV. Again, it sounds like you're going to need a more basic understanding of how to work with the pipeline, understand what options you have to work with objects, etc.

Running a Powershell script on multiple PCs

I have modified a script to standardise our organisations signatures in Outlook. The script uses a Word document as a template for the signature and extracts user details from the Active Directory info on our SBS 2003 server.
I am logged in as a Domain Admin and the script works ok for my Outlook signature (there are a couple of errors but it creates the 3x outlook signature files that I need). I can't get it to run on any other computer (but this is the only one with Powershell installed) nor will it run for any other user on this computer.
I would really like to be able to run the script from each workstation. This would be easy if it was a batch file, but it won't work as a powershell script. Do I need to install Powershell on every workstation or is there a simpler way to get it to work?
Also,
I wonder if there is a problem with the script that is not allowing other users to run it from this computer (even with Powershell installed).
Cheers,
Greg
Yes, you need Powershell installed on every machine where you want the script to run. It's included with OS on everything from Server 2008 and Windows 7, but otherwise you'll need to install Powershell manually.
You will also have to enable remote scripting on each machine, since this is disabled by default (for security reasons). Take a look at the following help pages for information and instructions on how to set up:
Get-Help about_remote
Get-Help about_remote_FAQ
Get-Help about_remote_requirements
Get-Help about_remote_troubleshooting
If you want to use PowerShell remotely you will need to install it. If you don't want to do that you could look at psexec - that's one of Sys Internals great tools. It will enable you to run commands\scripts remotely.
I have a different suggestion. Could you generate these signature files for your employees on your machine and then push the signatures out to all the other machines?