Get default printer remotely. You can use wmi. 32_printer to get the default. Nice post how to create windows service using PoserShell cmdlets http://www.yaplex.com/powershell/create-a-windows-service-using-powershell/. 12 June 2015. Deploying a Windows Service remotely with Powershell. As with any deployment automation, there’s a fair amount of duct tape and chicken wire involved. I have an.exe I would like to install on a large farm of Windows Server 2008 computers. I am attempting to use Powershell remoting. I have this command which works. Here is the code: $All. Printers = gwmi win. Default. Printer = $All. Printers | where {$_. Default - eq $true}. This will return all locally attached printers. If you want to get a list of network attached printers (as Aaron commented below), you run into a little bit of an issue.
The above script doesn't work because WMI operates on the local machine, and not on the user level. After much research, one way of getting this information is to have a log on script that runs, because there is essentially no other way of remotely using WMI to get the logged in user's information. How to really do it if we can't use WMI? Use the back door. All the pertinent information is stored in the registry. The output may not be pretty, but it will give you all the information that we need. We are only concerned about 3 key locations: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\Current. Version\Print\Printers. This contains all Locally Installed printers. Forget about it, use the gwmi win. HKEY_CURRENT_USER\Printers\Settings. This contains all the Currently logged in User Installed printers. It does not have the default printer information. HKEY_CURRENT_USER\Software\Microsoft\Windows NT\Current. Version\Windows\Device. This is where to get the Currently logged in User Installed Default printer. This is what Aaron is specifically looking for. So, we can use Power. Shell to connect to the remote registry, and read the currently logged in user's default printer with the following script: $Computer = "c. Reg = [Microsoft. I’m well into my journey of discovering the capabilities of PowerShell DSC and Release Management’s DSC feature (See my previous posts: PowerShell DSC. Win. 32. Registry. Key]: :Open. Remote. Base. Key('currentuser', $Computer). Reg. Key= $Reg. Open. Sub. Key('Software\Microsoft\Windows NT\Current. Version\Windows'). Default. Printer = $Reg. Key. Get. Value("Device"). Default. Printer | Convert. From- Csv - Header Name, Provider, Order| Select Name. EDIT - to get a list of all printers- -- -To list all printers on the remote computer: $Computer = "c. Get Local Printers. Printers = @(Get- Wmi. Object win. 32_printer - computername $Computer | Select Name). Get List of Network Printers. Reg = [Microsoft. Win. 32. Registry. Key]: :Open. Remote. Base. Key('currentuser', $Computer). Reg. Key= $Reg. Open. Sub. Key('Printers\Settings'). Printers += @($Reg. Key. Get. Value. Names()). Output List of Printers. Write- Output $Printers | ft - Property @{Name="Printer Name"; Expression={$_. Name}} - Auto. Size. Get Default Printer. Reg = [Microsoft. Sub. Key('Software\Microsoft\Windows NT\Current. Version\Windows'). Default. Printer = $Reg. Key. Get. Value("Device"). Output the Default Printer. Write- Output $Default. Printer | Convert. From- Csv - Header Name, Provider, Order| Select Name | ft - Property @{Name="Default Printer Name"; Expression={$_. Name}} - Auto. Size. Question using psexec to install remotely using both exe and msi files - Windows. I know because it is not an msi file, but if I try that just as an exe it just hangs. So does it work at all in any circumstances, such as when you launch it on the desktop manually? Assuming NO user input is asked for, that the exe wrapper passes on command line arguments to the invoked msiexec and that everything is correct with the file then as others have mentioned given it's an exe shouldn't you run it directly? Have you tired. psexec \\travel. Networkdata\vpn setup\runmsi. Networkdata\vpn setup\runmsi. For ease of escaping and quotes I'd consider running on an UNC path without the spaces. Otherwise adjust above as desired. First attempts to run the file off the UNC, the second copies it from the UNC to the remote machine then runs it. Might be easier if you have the file locally and use the second method. EXE's can wrap MSI's. Often when they do they pass the command arguments to the to invoked MSI. So you MAY find that your /quiet and /norestart flags are passed on and work fine. My gut guess is the exe is goosed, expecting user input or isn't passing on the arguments supplied to it (I assume you've tried runmsi. Using PSExec with anything that requires user input can involve additional painful steps. Check your EXE when run; doesn't. Consider using the - i on PSexec then loging into the system with the same credentials to examine whats going on. You may be interested in this: http: //community. I often use psexec like this (- c - f - d) to copy over the msi files, leave them there on remote machines to then be triggered later. Networkdata\vpn setup\mymsi. This I know will fail (it is an MSI after all), but I don't wait around (- d) and in doing so it is left on the remote system rather than auto- deleted by psexec. Then using WMIC or this. Oh well you get the gist enough to start playing I'm sure.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
August 2016
Categories |