0

Powershell – Read Computergroups and add them on another Computer

Another small script to read the AD Groups of a Computer account and then add the Groups to another Computer. You Need Quest Admin Tools installed, or RSAT. If you use RSAT, just remove the Q in “QADMemberOF” and “QADGroupMember”

$Groups = get-QADMemberOf “WS01$”
$Groups | foreach{
if ($_.name -ne “Domain Computers”) {
  Add-QADGroupMember $_ -Member “WS02$”
}

Where “WS01$” has to be changed to the source Computername, following the $ sign and “WS02$” has to be changed to the Destination Computername, don’t Forget the $ at the End!

 

If you’re just curious about the computergroups, you can get them via Powershell like this:

Get-QADComputer $Computer -Properties Memberof | Select-Object -Expand memberof

 

 

0

Powershell – Show Mapped drives of remote machine (Win8/8.1 only)

Here again one line of code that could be very useful. unfortunately it only works on machines that are on Windows 8 or higher

get-wmiobject -class “Win32_MappedLogicalDisk” -namespace “root\CIMV2” -computername $Computername | Select DeviceID puttygen ,ProviderName

$Computername has to be changed to the machine Name you want to check. As always, local admin rights are needed and the Firewall has to be set correct.

if you Need more Information like size or free space, you can just run the command without the select part:

get-wmiobject -class “Win32_MappedLogicalDisk” -namespace “root\CIMV2” -computername $Computername

 

0

CMD – Run Powershell script with restricted executionpolicy

In Software deployment, you sometimes Need to script stuff. For now, most of the guys I know use Batch files. Because they are easy to use, and they know how to script in Batch. I prefer powershell. But there could be a Problem:

xyz.ps1 cannot be loaded because the execution of scripts is disabled on this System. Please see “get-help about_signing” for more Details.”

This means, that the script you try to run is blocked by your local executionpolicy. You could Change it with Set-Executionpolicy Unrestricted, but for that, you would Need Access to the machine and start powershell as admin. In Addition, you would Need to Change the Setting back after starting the script. There is a better way:

Use cmd: powershell -noprofile -ExecutionPolicy Bypass -File “C:\Path\Script.ps1”

The script now Bypasses the executionpolicy. You can just add the line of code in e.g. your batchfile. puttygen ssh