Tuesday, August 27, 2013

VBScript to Unlock Powershell

I know it sounds odd.  But if the execution policy for powershell is set to restricted you can't do an awful lot remotely and most of what I do is remote.  To top that off a lot of times the multitude of remote managment tools don't work when you're troubleshooting an issues.  So there are a couple ways to set execution policy remotely. 

A lot of times I'll just do a psexec to run 'powershell set-executionpolicy unrestricted' but sometimes I've had issues with that erroring out for some reason, where dropping a script to the local machine and kicking it off locally works.  I don't know why.  So here's the script I drop on the box and then I use psexec to run it.

'---------------------------------------------------------------------------
' PowerShell Unlocker                             
' AUTH: David Bennett                                                      
' WEB :
http://sccmbrokeit.blogspot.com/
'                                                                          
' THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY   
' KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE      
' IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR    
' PURPOSE.                                                                 
'                                                                          
' Use : cscript UnlockPowerShell.vbs                                       
' Desc: Just runs "Set-ExecutionPolicy Unrestricted" so that powershell    
' scripts will run. Needs to be ran outside of PSH                  
' The intent of this version is to be dropped on a system and remotely
' executed with PSEXEC                                               
'---------------------------------------------------------------------------

On Error Resume Next
Err.Clear
Dim objShell
set objShell = CreateObject("Wscript.shell")

strPS = "Powershell.exe Set-ExecutionPolicy Unrestricted"
objShell.Run(strPS,0)

Friday, August 23, 2013

Updated Server Inventory Report

Updated the query:


SELECT DISTINCT
             v_R_System.Netbios_Name0 AS Name,v_RA_System_SMSAssignedSites.SMS_Assigned_Sites0 AS SCCM_Site,
             v_GS_WORKSTATION_STATUS.LastHWScan AS SCCM_Scan,
            MAX(REVERSE(LEFT(REVERSE(v_RA_System_SystemOUName.System_OU_Name0), CHARINDEX('/', REVERSE(v_RA_System_SystemOUName.System_OU_Name0)) - 1))) AS OU,
             v_R_System.description0 AS Description, v_GS_COMPUTER_SYSTEM.Manufacturer0 AS Make,
             v_GS_COMPUTER_SYSTEM.Model0 AS Model ,v_GS_PC_BIOS.SerialNumber0 AS Serial,
             v_GS_PROCESSOR.Name0 AS Processor,ISNULL(v_GS_PROCESSOR.NumberOfCores0,1) AS Cores,
             MAX(Right(v_GS_PROCESSOR.DeviceID0,1))+1 AS NumProcs,v_R_System.Operating_System_Name_and0 AS OS,
             v_GS_OPERATING_SYSTEM.CSDVersion0 AS SP,v_GS_X86_PC_MEMORY.TotalPhysicalMemory0 AS TotMemMB,
             v_GS_LOGICAL_DISK.DeviceID0 AS Drive ,v_GS_LOGICAL_DISK.Size0 AS TotalGB, v_GS_LOGICAL_DISK.FreeSpace0 AS FreeGB
FROM   v_R_System LEFT JOIN
              v_RA_System_SystemOUName ON v_R_System.ResourceID = v_RA_System_SystemOUName.ResourceID LEFT JOIN
              v_RA_System_SMSAssignedSites ON v_R_System.ResourceID = v_RA_System_SMSAssignedSites.ResourceID LEFT JOIN
              v_GS_WORKSTATION_STATUS ON v_R_System.ResourceID = v_GS_WORKSTATION_STATUS.ResourceID LEFT JOIN
              v_GS_LOGICAL_DISK ON v_R_System.ResourceID = v_GS_LOGICAL_DISK.ResourceID LEFT JOIN
              v_GS_COMPUTER_SYSTEM ON v_R_System.ResourceID = v_GS_COMPUTER_SYSTEM.ResourceID LEFT JOIN
              v_GS_OPERATING_SYSTEM ON v_R_System.ResourceID = v_GS_OPERATING_SYSTEM.ResourceID LEFT JOIN
              v_GS_PC_BIOS ON v_R_System.ResourceID = v_GS_PC_BIOS.ResourceID LEFT JOIN
              v_GS_X86_PC_MEMORY ON v_R_System.ResourceID = v_GS_X86_PC_MEMORY.ResourceID LEFT JOIN
              v_GS_PROCESSOR ON v_R_System.ResourceID = v_GS_PROCESSOR.ResourceID
Where (NOT (v_GS_LOGICAL_DISK.DriveType0 = '2')) AND (NOT (v_GS_LOGICAL_DISK.DriveType0 = '5'))
GROUP BY v_R_System.description0, v_R_System.Netbios_Name0, v_RA_System_SMSAssignedSites.SMS_Assigned_Sites0,
              v_GS_WORKSTATION_STATUS.LastHWScan,  v_GS_COMPUTER_SYSTEM.Manufacturer0, v_GS_COMPUTER_SYSTEM.Model0,
              v_GS_PC_BIOS.SerialNumber0, v_GS_PROCESSOR.Name0, v_GS_PROCESSOR.NumberOfCores0, v_GS_OPERATING_SYSTEM.CSDVersion0,
              v_GS_X86_PC_MEMORY.TotalPhysicalMemory0, v_GS_LOGICAL_DISK.DeviceID0, v_GS_LOGICAL_DISK.Size0,
              v_GS_LOGICAL_DISK.FreeSpace0, v_R_System.Operating_System_Name_and0
HAVING      (v_R_System.Operating_System_Name_and0 LIKE N'%server%')
ORDER BY Name