├── README.md ├── vbs ├── playground │ ├── launch.vbs │ ├── PrintReports.exe │ ├── DPMUpdate.cmd │ ├── PrintReports.cmd │ ├── OSVersion.vbs │ ├── adsk.vbs │ ├── ListADObjects.vbs │ ├── procedures │ │ ├── AddRegKey.txt │ │ ├── DelRegKey.txt │ │ ├── WriteData.txt │ │ ├── AddRegVal.txt │ │ ├── DisplayMessage.txt │ │ ├── DisconnectDrives.txt │ │ ├── UpdateArray.txt │ │ ├── LogData.txt │ │ ├── MkDir.txt │ │ ├── DelFolder.txt │ │ ├── VariableLogic.txt │ │ ├── AddVar.txt │ │ ├── DiscoverObjects.txt │ │ ├── ListConnectedUsers.txt │ │ ├── BuildReport.txt │ │ ├── ChangePass.txt │ │ ├── ConnectPrinters.txt │ │ ├── DisconnectPrinters.txt │ │ ├── RegRead.txt │ │ ├── BuildOUs.txt │ │ ├── HandleError.txt │ │ ├── AddGroup.txt │ │ ├── RegDel.txt │ │ ├── RemoteAddVar.txt │ │ ├── DrivesByGroup.txt │ │ ├── ClearFolder.txt │ │ ├── FixDupRegEntry.txt │ │ ├── QueryAD.txt │ │ ├── MapPrinters.txt │ │ ├── ListNetwork.txt │ │ ├── GetEvents.vbs │ │ ├── ListFolders.txt │ │ ├── VariableWork.txt │ │ ├── DisplayEvents.txt │ │ ├── CreateADObject.txt │ │ ├── SecLog.txt │ │ ├── MapObjects.txt │ │ └── BuildArray.txt │ ├── addremove.vbs │ ├── listprint.vbs │ ├── functions │ │ ├── CheckFolder.txt │ │ ├── WMIPing.txt │ │ ├── RetrieveOU.txt │ │ ├── GetSerial.txt │ │ ├── RetrieveUser.txt │ │ ├── GetHost.txt │ │ ├── GetOwner.txt │ │ ├── RetrieveComputer.txt │ │ ├── CheckRam.txt │ │ ├── CheckVariable.txt │ │ ├── GetProp.txt │ │ ├── CheckFreeSpace.txt │ │ ├── GetUser.txt │ │ ├── AccountEnabled.txt │ │ ├── ListConnections.txt │ │ ├── GetMac.txt │ │ ├── SID2User.txt │ │ ├── NT4toDN.txt │ │ ├── ValidateHost.txt │ │ ├── GetIP.txt │ │ ├── ScriptDetails.txt │ │ ├── GetHostData.txt │ │ ├── GetSoftware.txt │ │ ├── GetInstalledSoftware.txt │ │ └── GetWMIData.txt │ ├── printers.vbs │ ├── PrintLogs.vbs │ ├── AD_Trust.vbs │ ├── wmi.vbs │ ├── user.vbs │ ├── ListVars.vbs │ ├── ListComputers.vbs │ ├── printjobs.vbs │ ├── WMIFilter.vbs │ ├── ports.vbs │ ├── dbtest.vbs │ ├── ListGroupAttributes.txt │ ├── inventory.vbs │ ├── drive.vbs │ ├── Bios.vbs │ ├── inventory1.vbs │ ├── ListObjectAttribs.vbs │ ├── os.vbs │ ├── Memory.vbs │ ├── sample-vbs.txt │ ├── sample.txt │ ├── RegWrite.vbs │ ├── Processor.vbs │ ├── ListSerials.vbs │ ├── ChasisTypeScript.vbs │ ├── BatteryScript.vbs │ └── file_stat.vbs └── production │ ├── wmiutils │ ├── FileManagement.txt │ ├── WMIPing.txt │ ├── ListPrinters.txt │ ├── ManageServices.txt │ ├── SystemCenter.vbs │ └── DisableNICPowerManagement.vbs │ ├── adutils │ ├── WriteData.txt │ ├── GetProp.txt │ ├── NT4toDN.txt │ ├── WriteData.vbs │ ├── QueryAD.txt │ └── ListObjectAttribs.vbs │ ├── utils │ ├── LogData.txt │ ├── ping.txt │ ├── Sendmail.txt │ ├── ScriptDetails.txt │ └── StartCommand.txt │ ├── MklinkhomeDirectory.vbs │ └── mfd.vbs ├── powershell ├── playground │ ├── Images.ps1 │ ├── New-Iso.ps1 │ ├── fileinfo.ps1 │ ├── firewall.ps1 │ ├── get-web.ps1 │ ├── list-vms.ps1 │ ├── vDiagram.ps1 │ ├── Edit-File.ps1 │ ├── Email-Users.ps1 │ ├── Get-EodXml.ps1 │ ├── Get-Image.ps1 │ ├── Get-SQlData.ps1 │ ├── Get-UpTime.ps1 │ ├── Get-Weather.ps1 │ ├── Sort-Images.ps1 │ ├── Untitled1.ps1 │ ├── WebPIMirror.ps1 │ ├── get-outlook.ps1 │ ├── import-dhcp.ps1 │ ├── rss-images.ps1 │ ├── EXIFFunctions.ps1 │ ├── EXIFTagSwitch.ps1 │ ├── GPOFunctions.ps1 │ ├── Get-DHCPLogs.ps1 │ ├── Get-IisState.ps1 │ ├── Get-LogonTime.ps1 │ ├── Get-OpenLdap.ps1 │ ├── Get-Printers.ps1 │ ├── Get-SQLServer.ps1 │ ├── SCOM-Queries.ps1 │ ├── Set-LogonTime.ps1 │ ├── Start-Monitor.ps1 │ ├── VisioLibrary.ps1 │ ├── get-markuptag.ps1 │ ├── ComputerReports.ps1 │ ├── Export-EWIData.ps1 │ ├── Get-DHCPLeases.ps1 │ ├── Get-DefragReport.ps1 │ ├── Get-GroupMembers.ps1 │ ├── Get-LogonEvents.ps1 │ ├── Get-PrinterLogs.ps1 │ ├── Get-QuotaCreep.ps1 │ ├── GetDefragReport.ps1 │ ├── ImagingLibrary.ps1 │ ├── IncidentLibrary.ps1 │ ├── MigrationReport.ps1 │ ├── NonMigratedUsers.ps1 │ ├── SPListFunctions.ps1 │ ├── WebPIFunctions.ps1 │ ├── fsutilLIbrary.psm1 │ ├── ClusterManagement.ps1 │ ├── CountUsersInGroup.ps1 │ ├── Get-LatestBIOSRev.ps1 │ ├── Get-LostConnection.ps1 │ ├── Get-PendingUpdates.ps1 │ ├── Get-RDPLoginEvents.ps1 │ ├── Import-BlogEngine.ps1 │ ├── New-IncidentReport.ps1 │ ├── PowerShellCharting.ps1 │ ├── Reset-HealthAgent.ps1 │ ├── Set-ShutdownMethod.ps1 │ ├── SoftwareInstalled.ps1 │ ├── Write-LogsToExcel.ps1 │ ├── CreateRPCPortMonitors.ps1 │ ├── Get-AddressConflict.ps1 │ ├── Get-DHCPFilteredMac.ps1 │ ├── Get-GainedConnection.ps1 │ ├── Get-InstalledSoftware.ps1 │ ├── Get-SessionFailures.ps1 │ ├── Parse-StorageReport.ps1 │ ├── Remove-PrintDrivers.ps1 │ ├── Reset-ComputerAccount.ps1 │ ├── Send-UserLogonTimes.ps1 │ ├── Update-VmFromTemplate.ps1 │ ├── gettinggroupmembers.ps1 │ ├── Get-EventsFromYesterday.ps1 │ ├── ListUsersInAdminGroups.ps1 │ ├── CreateLicensePortMonitors.ps1 │ ├── DirectoryEntryCredentials.ps1 │ ├── Enable-ApplicationServicesLog.ps1 │ ├── ScriptingGames │ │ └── 2011 │ │ │ ├── Get-PrivateBuildInfo.ps1 │ │ │ └── Get-ServicesThatPause.ps1 │ ├── Get-EventId14.ps1 │ ├── engrlab-ie.ps1 │ ├── OutlookCalendarModule.psm1 │ ├── Get-WindowsUpdatesLog.ps1 │ ├── PaperCutlogging.ps1 │ ├── mlbImport.ps1 │ ├── Start-GroupMaintenanceMode.ps1 │ ├── Update-SCCMSources.ps1 │ ├── clonevm.ps1 │ ├── simple-profile.ps1 │ ├── Get-logs.ps1 │ ├── Parse-AuditLogs.ps1 │ ├── Start-RSDataProcessing.ps1 │ ├── AzureSQLModule.ps1 │ ├── createvm.ps1 │ ├── Add-DomainGroupToLocalGroup.ps1 │ ├── mstsc.ps1 │ ├── Setup-Workstation.ps1 │ ├── Profile.ps1 │ ├── mlbData.ps1 │ ├── Get-EmptyUnlinkedGPO.ps1 │ ├── Setup-Retrosheet.ps1 │ ├── Sort-OldImages.ps1 │ └── Sccm-Logs.ps1 └── production │ ├── Disable-Ipv6.ps1 │ ├── Get-BingImage.ps1 │ ├── Check-DTSRegIssue.ps1 │ ├── Get-NetstatReport.ps1 │ ├── vcheck │ └── ad-plugins │ │ ├── 02 GetFSMO.ps1 │ │ ├── 04 GetGpos.ps1 │ │ ├── 01 GetADInfo.ps1 │ │ ├── ADStubLibrary.ps1 │ │ ├── 03 GetDomainAdmins.ps1 │ │ ├── 05 GetDomainControllers.ps1 │ │ └── 00 GetLibrary.ps1 │ ├── sample.ps1 │ ├── includes │ ├── CarsonADLibraries.psm1 │ └── PerformanceTesting.psm1 │ └── Get-BIOSReport.ps1 ├── .gitignore ├── wiki ├── GetBIOSReport.wiki ├── DellWebsiteFunctions.wiki ├── GetSisStatusReport.wiki ├── GetLocalProfiles.wiki ├── GetFreeDiskSpace.wiki ├── NewPrintJob.wiki ├── FindLocalAdmins.wiki ├── createsite.wiki ├── GetOutageDuration.wiki ├── GetDHCPDenies.wiki ├── GetDomainUsers.wiki └── UpdateVmFromTemplate.wiki └── PSMA └── o365 └── New-Schema.ps1 /README.md: -------------------------------------------------------------------------------- 1 | mod-posh 2 | ======== 3 | -------------------------------------------------------------------------------- /vbs/playground/launch.vbs: -------------------------------------------------------------------------------- 1 | Set objShell = CreateObject("Wscript.Shell") 2 | 3 | objShell.Run "files.hta" -------------------------------------------------------------------------------- /powershell/playground/Images.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Images.ps1 -------------------------------------------------------------------------------- /vbs/playground/PrintReports.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/vbs/playground/PrintReports.exe -------------------------------------------------------------------------------- /powershell/playground/New-Iso.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/New-Iso.ps1 -------------------------------------------------------------------------------- /powershell/playground/fileinfo.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/fileinfo.ps1 -------------------------------------------------------------------------------- /powershell/playground/firewall.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/firewall.ps1 -------------------------------------------------------------------------------- /powershell/playground/get-web.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/get-web.ps1 -------------------------------------------------------------------------------- /powershell/playground/list-vms.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/list-vms.ps1 -------------------------------------------------------------------------------- /powershell/playground/vDiagram.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/vDiagram.ps1 -------------------------------------------------------------------------------- /powershell/playground/Edit-File.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Edit-File.ps1 -------------------------------------------------------------------------------- /powershell/playground/Email-Users.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Email-Users.ps1 -------------------------------------------------------------------------------- /powershell/playground/Get-EodXml.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Get-EodXml.ps1 -------------------------------------------------------------------------------- /powershell/playground/Get-Image.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Get-Image.ps1 -------------------------------------------------------------------------------- /powershell/playground/Get-SQlData.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Get-SQlData.ps1 -------------------------------------------------------------------------------- /powershell/playground/Get-UpTime.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Get-UpTime.ps1 -------------------------------------------------------------------------------- /powershell/playground/Get-Weather.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Get-Weather.ps1 -------------------------------------------------------------------------------- /powershell/playground/Sort-Images.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Sort-Images.ps1 -------------------------------------------------------------------------------- /powershell/playground/Untitled1.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Untitled1.ps1 -------------------------------------------------------------------------------- /powershell/playground/WebPIMirror.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/WebPIMirror.ps1 -------------------------------------------------------------------------------- /powershell/playground/get-outlook.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/get-outlook.ps1 -------------------------------------------------------------------------------- /powershell/playground/import-dhcp.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/import-dhcp.ps1 -------------------------------------------------------------------------------- /powershell/playground/rss-images.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/rss-images.ps1 -------------------------------------------------------------------------------- /powershell/playground/EXIFFunctions.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/EXIFFunctions.ps1 -------------------------------------------------------------------------------- /powershell/playground/EXIFTagSwitch.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/EXIFTagSwitch.ps1 -------------------------------------------------------------------------------- /powershell/playground/GPOFunctions.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/GPOFunctions.ps1 -------------------------------------------------------------------------------- /powershell/playground/Get-DHCPLogs.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Get-DHCPLogs.ps1 -------------------------------------------------------------------------------- /powershell/playground/Get-IisState.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Get-IisState.ps1 -------------------------------------------------------------------------------- /powershell/playground/Get-LogonTime.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Get-LogonTime.ps1 -------------------------------------------------------------------------------- /powershell/playground/Get-OpenLdap.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Get-OpenLdap.ps1 -------------------------------------------------------------------------------- /powershell/playground/Get-Printers.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Get-Printers.ps1 -------------------------------------------------------------------------------- /powershell/playground/Get-SQLServer.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Get-SQLServer.ps1 -------------------------------------------------------------------------------- /powershell/playground/SCOM-Queries.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/SCOM-Queries.ps1 -------------------------------------------------------------------------------- /powershell/playground/Set-LogonTime.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Set-LogonTime.ps1 -------------------------------------------------------------------------------- /powershell/playground/Start-Monitor.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Start-Monitor.ps1 -------------------------------------------------------------------------------- /powershell/playground/VisioLibrary.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/VisioLibrary.ps1 -------------------------------------------------------------------------------- /powershell/playground/get-markuptag.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/get-markuptag.ps1 -------------------------------------------------------------------------------- /powershell/production/Disable-Ipv6.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/production/Disable-Ipv6.ps1 -------------------------------------------------------------------------------- /powershell/production/Get-BingImage.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/production/Get-BingImage.ps1 -------------------------------------------------------------------------------- /powershell/playground/ComputerReports.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/ComputerReports.ps1 -------------------------------------------------------------------------------- /powershell/playground/Export-EWIData.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Export-EWIData.ps1 -------------------------------------------------------------------------------- /powershell/playground/Get-DHCPLeases.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Get-DHCPLeases.ps1 -------------------------------------------------------------------------------- /powershell/playground/Get-DefragReport.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Get-DefragReport.ps1 -------------------------------------------------------------------------------- /powershell/playground/Get-GroupMembers.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Get-GroupMembers.ps1 -------------------------------------------------------------------------------- /powershell/playground/Get-LogonEvents.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Get-LogonEvents.ps1 -------------------------------------------------------------------------------- /powershell/playground/Get-PrinterLogs.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Get-PrinterLogs.ps1 -------------------------------------------------------------------------------- /powershell/playground/Get-QuotaCreep.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Get-QuotaCreep.ps1 -------------------------------------------------------------------------------- /powershell/playground/GetDefragReport.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/GetDefragReport.ps1 -------------------------------------------------------------------------------- /powershell/playground/ImagingLibrary.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/ImagingLibrary.ps1 -------------------------------------------------------------------------------- /powershell/playground/IncidentLibrary.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/IncidentLibrary.ps1 -------------------------------------------------------------------------------- /powershell/playground/MigrationReport.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/MigrationReport.ps1 -------------------------------------------------------------------------------- /powershell/playground/NonMigratedUsers.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/NonMigratedUsers.ps1 -------------------------------------------------------------------------------- /powershell/playground/SPListFunctions.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/SPListFunctions.ps1 -------------------------------------------------------------------------------- /powershell/playground/WebPIFunctions.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/WebPIFunctions.ps1 -------------------------------------------------------------------------------- /powershell/playground/fsutilLIbrary.psm1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/fsutilLIbrary.psm1 -------------------------------------------------------------------------------- /powershell/playground/ClusterManagement.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/ClusterManagement.ps1 -------------------------------------------------------------------------------- /powershell/playground/CountUsersInGroup.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/CountUsersInGroup.ps1 -------------------------------------------------------------------------------- /powershell/playground/Get-LatestBIOSRev.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Get-LatestBIOSRev.ps1 -------------------------------------------------------------------------------- /powershell/playground/Get-LostConnection.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Get-LostConnection.ps1 -------------------------------------------------------------------------------- /powershell/playground/Get-PendingUpdates.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Get-PendingUpdates.ps1 -------------------------------------------------------------------------------- /powershell/playground/Get-RDPLoginEvents.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Get-RDPLoginEvents.ps1 -------------------------------------------------------------------------------- /powershell/playground/Import-BlogEngine.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Import-BlogEngine.ps1 -------------------------------------------------------------------------------- /powershell/playground/New-IncidentReport.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/New-IncidentReport.ps1 -------------------------------------------------------------------------------- /powershell/playground/PowerShellCharting.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/PowerShellCharting.ps1 -------------------------------------------------------------------------------- /powershell/playground/Reset-HealthAgent.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Reset-HealthAgent.ps1 -------------------------------------------------------------------------------- /powershell/playground/Set-ShutdownMethod.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Set-ShutdownMethod.ps1 -------------------------------------------------------------------------------- /powershell/playground/SoftwareInstalled.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/SoftwareInstalled.ps1 -------------------------------------------------------------------------------- /powershell/playground/Write-LogsToExcel.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Write-LogsToExcel.ps1 -------------------------------------------------------------------------------- /powershell/production/Check-DTSRegIssue.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/production/Check-DTSRegIssue.ps1 -------------------------------------------------------------------------------- /powershell/production/Get-NetstatReport.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/production/Get-NetstatReport.ps1 -------------------------------------------------------------------------------- /vbs/playground/DPMUpdate.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | "c:\Program Files\Microsoft Data Protection Manager\DPM\bin\SetDpmServer.exe" -dpmServerName backup 3 | -------------------------------------------------------------------------------- /powershell/playground/CreateRPCPortMonitors.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/CreateRPCPortMonitors.ps1 -------------------------------------------------------------------------------- /powershell/playground/Get-AddressConflict.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Get-AddressConflict.ps1 -------------------------------------------------------------------------------- /powershell/playground/Get-DHCPFilteredMac.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Get-DHCPFilteredMac.ps1 -------------------------------------------------------------------------------- /powershell/playground/Get-GainedConnection.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Get-GainedConnection.ps1 -------------------------------------------------------------------------------- /powershell/playground/Get-InstalledSoftware.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Get-InstalledSoftware.ps1 -------------------------------------------------------------------------------- /powershell/playground/Get-SessionFailures.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Get-SessionFailures.ps1 -------------------------------------------------------------------------------- /powershell/playground/Parse-StorageReport.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Parse-StorageReport.ps1 -------------------------------------------------------------------------------- /powershell/playground/Remove-PrintDrivers.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Remove-PrintDrivers.ps1 -------------------------------------------------------------------------------- /powershell/playground/Reset-ComputerAccount.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Reset-ComputerAccount.ps1 -------------------------------------------------------------------------------- /powershell/playground/Send-UserLogonTimes.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Send-UserLogonTimes.ps1 -------------------------------------------------------------------------------- /powershell/playground/Update-VmFromTemplate.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Update-VmFromTemplate.ps1 -------------------------------------------------------------------------------- /powershell/playground/gettinggroupmembers.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/gettinggroupmembers.ps1 -------------------------------------------------------------------------------- /powershell/playground/Get-EventsFromYesterday.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Get-EventsFromYesterday.ps1 -------------------------------------------------------------------------------- /powershell/playground/ListUsersInAdminGroups.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/ListUsersInAdminGroups.ps1 -------------------------------------------------------------------------------- /powershell/playground/CreateLicensePortMonitors.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/CreateLicensePortMonitors.ps1 -------------------------------------------------------------------------------- /powershell/playground/DirectoryEntryCredentials.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/DirectoryEntryCredentials.ps1 -------------------------------------------------------------------------------- /powershell/production/vcheck/ad-plugins/02 GetFSMO.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/production/vcheck/ad-plugins/02 GetFSMO.ps1 -------------------------------------------------------------------------------- /powershell/production/vcheck/ad-plugins/04 GetGpos.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/production/vcheck/ad-plugins/04 GetGpos.ps1 -------------------------------------------------------------------------------- /vbs/playground/PrintReports.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | echo This utility generates c:\reports.csv 3 | echo Working... 4 | PrintReports.exe > c:\reports.csv 5 | echo Done. -------------------------------------------------------------------------------- /powershell/playground/Enable-ApplicationServicesLog.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/Enable-ApplicationServicesLog.ps1 -------------------------------------------------------------------------------- /powershell/production/vcheck/ad-plugins/01 GetADInfo.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/production/vcheck/ad-plugins/01 GetADInfo.ps1 -------------------------------------------------------------------------------- /powershell/production/vcheck/ad-plugins/ADStubLibrary.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/production/vcheck/ad-plugins/ADStubLibrary.ps1 -------------------------------------------------------------------------------- /powershell/production/vcheck/ad-plugins/03 GetDomainAdmins.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/production/vcheck/ad-plugins/03 GetDomainAdmins.ps1 -------------------------------------------------------------------------------- /powershell/playground/ScriptingGames/2011/Get-PrivateBuildInfo.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/ScriptingGames/2011/Get-PrivateBuildInfo.ps1 -------------------------------------------------------------------------------- /powershell/playground/ScriptingGames/2011/Get-ServicesThatPause.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/playground/ScriptingGames/2011/Get-ServicesThatPause.ps1 -------------------------------------------------------------------------------- /powershell/production/vcheck/ad-plugins/05 GetDomainControllers.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffpatton1971/mod-posh/HEAD/powershell/production/vcheck/ad-plugins/05 GetDomainControllers.ps1 -------------------------------------------------------------------------------- /powershell/playground/Get-EventId14.ps1: -------------------------------------------------------------------------------- 1 | $Users = foreach ($Item in (Get-WinEvent -FilterHashtable @{Logname='System';ID=14} )){$Item.Properties[1]} 2 | $Users |Sort-Object -Property Value -Unique -------------------------------------------------------------------------------- /vbs/playground/OSVersion.vbs: -------------------------------------------------------------------------------- 1 | On error resume next 2 | strVersion = GetObject("winmgmts:win32_OperatingSystem=@").Caption 3 | 4 | If strVersion = "" Then 5 | Wscript.Echo "Windows XP" 6 | Else 7 | Wscript.Echo strversion 8 | End If -------------------------------------------------------------------------------- /vbs/playground/adsk.vbs: -------------------------------------------------------------------------------- 1 | Set objShell = WScript.CreateObject("WScript.Shell") 2 | objShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\ADSKFLEX_LICENSE_FILE", "@license1.soecs.ku.edu", "REG_SZ" 3 | 4 | 5 | -------------------------------------------------------------------------------- /powershell/playground/engrlab-ie.ps1: -------------------------------------------------------------------------------- 1 | $shell = New-Object -com "Shell.Application" 2 | $cookies = ($shell.namespace(0x21)).Self.Path 3 | remove-item $cookies\*.* -force 4 | $ie = new-object -com "InternetExplorer.Application" 5 | $ie.fullscreen =$true 6 | $ie.visible = $true -------------------------------------------------------------------------------- /vbs/playground/ListADObjects.vbs: -------------------------------------------------------------------------------- 1 | Set colItems = GetObject("LDAP://OU=1,OU=Eaton,OU=People,DC=company,DC=com") 2 | 3 | For Each objItem in colItems 4 | If objItem.UNCName <> "" Then 5 | wscript.Echo objItem.Name 6 | Wscript.Echo objItem.UNCName 7 | End If 8 | Next 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # This .gitignore file was automatically created by Microsoft(R) Visual Studio. 3 | ################################################################################ 4 | 5 | /.vs/slnx.sqlite 6 | -------------------------------------------------------------------------------- /wiki/GetBIOSReport.wiki: -------------------------------------------------------------------------------- 1 | = !Get-BIOSReport.ps1 = 2 | {{{ 3 | Get-BIOSReport.ps1 [-ADSPath] [-Verbose] [-Debug] [-ErrorAction ] [-WarningAction ] [-ErrorVariable ] [-WarningVariable ] [-OutVariable ] [-OutBuffer ] 4 | 5 | }}} 6 | -------------------------------------------------------------------------------- /vbs/playground/procedures/AddRegKey.txt: -------------------------------------------------------------------------------- 1 | Sub AddRegKey(strRegistry) 2 | ' 3 | ' Add Registry key 4 | ' 5 | Const HKEY_LOCAL_MACHINE = &H80000002 6 | Dim objRegistry 7 | 8 | Set objRegistry = GetObject("winmgmts:\\.\root\default:StdRegProv") 9 | 10 | objRegistry.CreateKey HKEY_LOCAL_MACHINE, strRegistry 11 | End Sub -------------------------------------------------------------------------------- /vbs/production/wmiutils/FileManagement.txt: -------------------------------------------------------------------------------- 1 | ' 2 | ' File Management subroutines 3 | ' 4 | ' Below is a collection of useful file utilies. 5 | ' 6 | Sub DeleteFile(strCompleteFilePath) 7 | Dim objFSO 8 | 9 | Set objFSO = CreateObject("Scripting.FileSystemObject") 10 | objFSO.DeleteFile(strCompleteFilePath) 11 | End Sub -------------------------------------------------------------------------------- /vbs/playground/procedures/DelRegKey.txt: -------------------------------------------------------------------------------- 1 | Sub DelRegKey(strRegistry) 2 | ' 3 | ' Delete Registry Key 4 | ' 5 | Const HKEY_LOCAL_MACHINE = &H80000002 6 | Dim objRegistry 7 | 8 | Set objRegistry=GetObject("winmgmts:\\.\root\default:StdRegProv") 9 | 10 | objRegistry.DeleteKey HKEY_LOCAL_MACHINE, strRegistry 11 | End Sub -------------------------------------------------------------------------------- /vbs/playground/addremove.vbs: -------------------------------------------------------------------------------- 1 | strComputer = "l3150-pc01.soecs.ku.edu" 2 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 3 | Set colItems = objWMIService.ExecQuery( _ 4 | "SELECT * FROM Win32_Product",,48) 5 | For Each objItem in colItems 6 | Wscript.Echo objItem.Caption & ", " & objItem.Description 7 | Next -------------------------------------------------------------------------------- /vbs/production/adutils/WriteData.txt: -------------------------------------------------------------------------------- 1 | Sub WriteData(strProperty, strValue, strADSPath) 2 | ' 3 | ' Update a single-value property of an object in AD 4 | ' 5 | Dim objADObject 6 | 7 | Set objADObject = GetObject("LDAP://" & strADSPath) 8 | 9 | objADObject.Put strProperty , strValue 10 | objADObject.SetInfo 11 | 12 | End Sub -------------------------------------------------------------------------------- /vbs/playground/procedures/WriteData.txt: -------------------------------------------------------------------------------- 1 | Sub WriteData(strProperty, strValue, strADSPath) 2 | ' 3 | ' Update a single-value property of an object in AD 4 | ' 5 | Dim objADObject 6 | 7 | Set objADObject = GetObject("LDAP://" & strADSPath) 8 | 9 | objADObject.Put strProperty , strValue 10 | objADObject.SetInfo 11 | 12 | End Sub -------------------------------------------------------------------------------- /vbs/playground/procedures/AddRegVal.txt: -------------------------------------------------------------------------------- 1 | Sub AddRegVal(strRegistry, strValueName, szValue) 2 | ' 3 | ' Add registry value 4 | ' 5 | Const HKEY_LOCAL_MACHINE = &H80000002 6 | Dim objRegistry 7 | 8 | Set objRegistry = GetObject("winmgmts:\\.\root\default:StdRegProv") 9 | 10 | objRegistry.SetStringValue HKEY_LOCAL_MACHINE, strRegistry, strValueName, szValue 11 | End Sub -------------------------------------------------------------------------------- /powershell/playground/OutlookCalendarModule.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | https://blogs.technet.microsoft.com/heyscriptingguy/2011/05/24/use-powershell-to-export-outlook-calendar-information/ 3 | https://docs.microsoft.com/en-us/sysinternals/downloads/bginfo 4 | https://weblogs.asp.net/whaggard/retrieving-your-outlook-appointments-for-a-given-date-range 5 | https://msdn.microsoft.com/en-us/library/bb206775.aspx 6 | #> -------------------------------------------------------------------------------- /vbs/playground/procedures/DisplayMessage.txt: -------------------------------------------------------------------------------- 1 | Sub DisplayMessage 2 | ' 3 | ' Displays a custom HTA 4 | ' 5 | Dim objFSO 6 | Dim objShell 7 | 8 | Set objFSO = CreateObject("Scripting.FileSystemObject") 9 | 10 | If objFSO.FileExists("message.hta") Then 11 | Set objShell = CreateObject("Wscript.Shell") 12 | objShell.Run "message.hta" 13 | Else 14 | End If 15 | End Sub -------------------------------------------------------------------------------- /vbs/playground/procedures/DisconnectDrives.txt: -------------------------------------------------------------------------------- 1 | Sub DisconnectDrives 2 | Dim objNetwork 3 | Dim colDrives 4 | Dim i 5 | 6 | On Error Resume Next 7 | Set objNetwork = CreateObject("Wscript.Network") 8 | Set colDrives = objNetwork.EnumNetworkDrives 9 | 10 | For i = 0 to (colDrives.Count -1) Step 2 11 | objNetwork.RemoveNetworkDrive colDrives.Item(i) 12 | Next 13 | 14 | End Sub -------------------------------------------------------------------------------- /vbs/playground/listprint.vbs: -------------------------------------------------------------------------------- 1 | strComputer = "." 2 | 3 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") 4 | 5 | Set colPrinters = objWMIService.ExecQuery("Select * From Win32_Printer") 6 | 7 | Wscript.Echo "Printer,Print Port,Driver" 8 | For Each objPrinter in colPrinters 9 | wscript.echo objPrinter.Name & vbtab & objPrinter.PortName ' & "," & objPrinter.DriverName 10 | Next -------------------------------------------------------------------------------- /vbs/playground/procedures/UpdateArray.txt: -------------------------------------------------------------------------------- 1 | Sub UpdateArray(strADSPath, intArrIndex, strLab) 2 | arrLabs(intArrIndex,0) = strLab 3 | arrLabs(intArrIndex,1) = arrLabs(intArrIndex,1) + 1 4 | strValue = GetProp(strADSPath, "Description") 5 | Select Case strValue 6 | Case "FREE" 7 | arrLabs(intArrIndex,2) = arrLabs(intArrIndex,2) + 1 8 | Case "OFFLINE" 9 | arrLabs(intArrIndex,3) = arrLabs(intArrIndex,3) + 1 10 | End Select 11 | End Sub -------------------------------------------------------------------------------- /vbs/production/utils/LogData.txt: -------------------------------------------------------------------------------- 1 | Sub LogData(intCode, strMessage) 2 | ' Write data to application log 3 | ' 4 | ' http://www.microsoft.com/technet/scriptcenter/guide/default.mspx?mfr=true 5 | ' 6 | ' Event Codes 7 | ' 0 = Success 8 | ' 1 = Error 9 | ' 2 = Warning 10 | ' 4 = Information 11 | Dim objShell 12 | 13 | Set objShell = Wscript.CreateObject("Wscript.Shell") 14 | 15 | objShell.LogEvent intCode, strMessage 16 | 17 | End Sub -------------------------------------------------------------------------------- /vbs/playground/functions/CheckFolder.txt: -------------------------------------------------------------------------------- 1 | Function CheckFolder(strPath) 2 | ' 3 | ' This function returns vbTrue or vbFalse based on whether or not it finds the folder 4 | ' 5 | Dim blnFound 6 | Dim objFSO 7 | Dim objFolder 8 | 9 | blnFound = vbFalse 10 | Set objFSO = CreateObject("Scripting.FileSystemObject") 11 | 12 | If objFSO.FolderExists(strPath) Then 13 | blnFound = vbTrue 14 | End If 15 | 16 | CheckFolder = blnFound 17 | End Function -------------------------------------------------------------------------------- /vbs/playground/procedures/LogData.txt: -------------------------------------------------------------------------------- 1 | Sub LogData(intCode, strMessage) 2 | ' Write data to application log 3 | ' 4 | ' http://www.microsoft.com/technet/scriptcenter/guide/default.mspx?mfr=true 5 | ' 6 | ' Event Codes 7 | ' 0 = Success 8 | ' 1 = Error 9 | ' 2 = Warning 10 | ' 4 = Information 11 | Dim objShell 12 | 13 | Set objShell = Wscript.CreateObject("Wscript.Shell") 14 | 15 | objShell.LogEvent intCode, strMessage 16 | 17 | End Sub -------------------------------------------------------------------------------- /vbs/playground/functions/WMIPing.txt: -------------------------------------------------------------------------------- 1 | Function WMIPing(strComputer) 2 | ' 3 | ' Is computer online? 4 | ' 5 | ' Attempt WMI Connection if it fails ComputerOnline = False 6 | ' 7 | Dim blnOnline 8 | Dim objWMIService 9 | 10 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 11 | If Err <> 0 Then 12 | blnOnline = vbFalse 13 | Else 14 | blnOnline = vbTrue 15 | End If 16 | 17 | ComputerOnline = blnOnline 18 | End Function -------------------------------------------------------------------------------- /vbs/production/wmiutils/WMIPing.txt: -------------------------------------------------------------------------------- 1 | Function WMIPing(strComputer) 2 | ' 3 | ' Is computer online? 4 | ' 5 | ' Attempt WMI Connection if it fails ComputerOnline = False 6 | ' 7 | Dim blnOnline 8 | Dim objWMIService 9 | 10 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 11 | If Err <> 0 Then 12 | blnOnline = vbFalse 13 | Else 14 | blnOnline = vbTrue 15 | End If 16 | 17 | ComputerOnline = blnOnline 18 | End Function -------------------------------------------------------------------------------- /powershell/playground/Get-WindowsUpdatesLog.ps1: -------------------------------------------------------------------------------- 1 | $WindowsUpdateLogs = Import-Csv C:\Windows\WindowsUpdate.log -Delimiter `t -Header "Date","Time","PID","TID","Component","Text" 2 | $WindowsUpdateLogs |Where-Object {$_.Date -eq '2012-10-18'} |Format-Table -AutoSize -Property Date, Time, Text 3 | 4 | Import-Csv C:\Windows\WindowsUpdate.log -Delimiter `t -Header "Date","Time","PID","TID","Component","Text" |Where-Object {$_.Date -eq '2012-10-18'} |Format-Table -AutoSize -Property Date, Time, Text -------------------------------------------------------------------------------- /vbs/playground/procedures/MkDir.txt: -------------------------------------------------------------------------------- 1 | Sub MkDir(strPath) 2 | On Error Resume Next 3 | Dim objFSO 4 | Dim objFolder 5 | 6 | Set objFSO = CreateObject("Scripting.FileSystemObject") 7 | Set objFolder = objFSO.CreateFolder(strPath) 8 | 9 | If Err <> 0 Then 10 | Call LogData(1, "Unable to create: '" & strPath & vbCrLf & "'" & "Error Number: " & vbTab & Err.Number & vbCrLf & "Error Description: " & vbTab & Err.Description) 11 | Err.Clear 12 | Exit Sub 13 | End IF 14 | End Sub -------------------------------------------------------------------------------- /vbs/playground/functions/RetrieveOU.txt: -------------------------------------------------------------------------------- 1 | Function RetrieveOU() 2 | ' Retrieve computer OU 3 | ' 4 | ' http://www.microsoft.com/technet/scriptcenter/resources/qanda/jul07/hey0727.mspx 5 | ' 6 | Dim objSysInfo 7 | Dim strName 8 | Dim strOU 9 | 10 | On Error Resume Next 11 | set objSysInfo = CreateObject("ADSystemInfo") 12 | 13 | strName = objSysInfo.ComputerName 14 | 15 | strOU = Right(strName, Len(strName) - InStr(strName, ",")) 16 | RetrieveOU = strOU 17 | 18 | End Function -------------------------------------------------------------------------------- /vbs/playground/procedures/DelFolder.txt: -------------------------------------------------------------------------------- 1 | Sub DelFolder(strPath) 2 | ' 3 | ' Deletes a given folder from the disk. 4 | ' 5 | On Error Resume Next 6 | Dim objFSO 7 | 8 | Set objFSO = CreateObject("Scripting.FileSystemObject") 9 | 10 | objFSO.DeleteFolder strPath, True 11 | If Err <> 0 Then 12 | Call LogData(1, "Error deleteing " & strPath & vbCrLf & Err.Number & vbCrLf & Err.Description) 13 | Err.Clear 14 | Else 15 | Call LogData(0, "Deleted: " & strPath) 16 | End If 17 | End Sub -------------------------------------------------------------------------------- /vbs/playground/procedures/VariableLogic.txt: -------------------------------------------------------------------------------- 1 | Sub VariableLogic(strComputer, strUserName, strVarName, strVarValue) 2 | ' 3 | ' This procedure determines if we should update or create a given ENV variable 4 | ' based on whether or not it already exists. 5 | ' 6 | If CheckVariable(strVarName) = vbTrue Then 7 | Call VariableWork(strComputer, strUserName, strVarName, strVarValue, "UPDATE") 8 | Else 9 | Call VariableWork(strComputer, strUserName, strVarName, strVarValue, "CREATE") 10 | End If 11 | End Sub -------------------------------------------------------------------------------- /vbs/playground/functions/GetSerial.txt: -------------------------------------------------------------------------------- 1 | Function GetSerial(strComputer) 2 | ' 3 | ' Get serial number from the BIOS 4 | ' 5 | Dim strSerial 6 | Dim objWMIService 7 | Dim colItems 8 | Dim objItem 9 | 10 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 11 | Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_BIOS",,48) 12 | 13 | For Each objItem in colItems 14 | strSerial = objItem.SerialNumber 15 | Next 16 | 17 | GetSerial = strSerial 18 | End Function -------------------------------------------------------------------------------- /vbs/playground/functions/RetrieveUser.txt: -------------------------------------------------------------------------------- 1 | Function RetrieveUser() 2 | Dim objWMIService 3 | Dim colItems 4 | Dim objItem 5 | Dim arrUser 6 | Dim strUser 7 | 8 | On Error Resume Next 9 | Set objWMIService = GetObject("winmgmts:\\.\root\cimv2") 10 | Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem") 11 | 12 | For Each objItem in colItems 13 | arrUser = Split(objItem.UserName, "\") 14 | strUser = arrUser(1) 15 | Next 16 | 17 | RetrieveUser = strUser 18 | 19 | End Function -------------------------------------------------------------------------------- /vbs/playground/procedures/AddVar.txt: -------------------------------------------------------------------------------- 1 | Sub AddVar(strRegPath, strVariable, strVariableValue, strVariableType) 2 | ' 3 | ' This procedure adds environment variables reliably 4 | ' 5 | ' http://msdn.microsoft.com/en-us/library/yfdfhz1b(VS.85).aspx 6 | ' 7 | Dim WshShell 8 | Set WshShell = WScript.CreateObject("WScript.Shell") 9 | 10 | WshShell.RegWrite strRegPath & strVariable, strVariableValue, strVariableType 11 | If Err <> 0 Then Call LogData(1, "Unable to add " & strvariable & " = " & strVariableValue) 12 | 13 | End Sub -------------------------------------------------------------------------------- /vbs/playground/functions/GetHost.txt: -------------------------------------------------------------------------------- 1 | Function GetHost(strComputer) 2 | ' 3 | ' Get host name of the computer 4 | ' 5 | Dim objWMIService 6 | Dim colItems 7 | Dim objItem 8 | Dim strHost 9 | 10 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 11 | Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration Where IPEnabled = True",,48) 12 | 13 | For Each objItem in colItems 14 | strHost = objItem.DNSHostName 15 | Next 16 | 17 | GetHost = strHost 18 | End Function -------------------------------------------------------------------------------- /vbs/playground/functions/GetOwner.txt: -------------------------------------------------------------------------------- 1 | Function GetOwner(strComputerDN) 2 | ' 3 | ' This function returns the owner of a computer object 4 | ' 5 | ' Source, Richard Mueller 6 | ' http://social.technet.microsoft.com/Forums/en-us/ITCG/thread/59159984-729c-46d1-8faa-58c71ac3a209 7 | ' 8 | Dim objADObject 9 | Dim objSecurityDescriptor 10 | 11 | set objADObject = GetObject("LDAP://" & strComputerDN) 12 | set objSecurityDescriptor = objADObject.Get("ntSecurityDescriptor") 13 | 14 | GetOwner = objSecurityDescriptor.Owner 15 | End Function 16 | -------------------------------------------------------------------------------- /vbs/playground/functions/RetrieveComputer.txt: -------------------------------------------------------------------------------- 1 | Function RetrieveComputer() 2 | ' 3 | ' Pulls the ComputerName from the system info AD object 4 | ' Strips off everything after the computername 5 | ' Strips off everything in front of computername 6 | ' 7 | Dim objSysInfo 8 | Dim strComputerName 9 | set objSysInfo = CreateObject("ADSystemInfo") 10 | 11 | strComputerName = Left(objSysInfo.ComputerName, InStr(objSysInfo.ComputerName, ",")- 1) 12 | RetrieveComputer = Right(strComputerName, Len(strComputerName) - 3) 13 | 14 | End Function -------------------------------------------------------------------------------- /vbs/playground/printers.vbs: -------------------------------------------------------------------------------- 1 | ' 2 | ' Mapping Printers 3 | ' 4 | ' This script will check for default printers and map additional printers as needed. 5 | ' 6 | ' August 13, 2008: Jeff Patton 7 | ' 8 | 9 | Sub ConnectPrinter 10 | ' 11 | ' This procedure maps printers 12 | ' 13 | End Sub 14 | 15 | Sub DisconnectPrinter 16 | ' 17 | ' This procedure unmaps printers 18 | ' 19 | End Sub 20 | 21 | Function DefaultPrinter 22 | ' 23 | ' This function returns the default printer 24 | ' 25 | DefaultPrinter = 26 | End Function 27 | 28 | -------------------------------------------------------------------------------- /vbs/playground/procedures/DiscoverObjects.txt: -------------------------------------------------------------------------------- 1 | Sub DiscoverObjects(strURL) 2 | ' 3 | ' Locate all objects that have a UNCName property 4 | ' 5 | On Error Resume Next 6 | Dim colItems 7 | Dim objItem 8 | 9 | Set colItems = GetObject("LDAP://" & strURL) 10 | If Err <> 0 Then 11 | Call LogData(1, Err.Number & vbCrLf & Err.Description) 12 | Err.Clear 13 | End If 14 | 15 | For Each objItem in colItems 16 | If objItem.UNCName <> "" Then 17 | Call MapObject(objItem.UNCName, objItem.CN) 18 | End If 19 | Next 20 | End Sub 21 | -------------------------------------------------------------------------------- /vbs/playground/procedures/ListConnectedUsers.txt: -------------------------------------------------------------------------------- 1 | Sub ListConnectedUsers(strComputer, strShare) 2 | ' 3 | ' This procedure returns the users connected to a given share 4 | ' 5 | Dim objWMIService 6 | Dim colItems 7 | Dim objItem 8 | 9 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 10 | Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ServerConnection WHERE ShareName = '" & strShare & "'",,48) 11 | 12 | For Each objItem in colItems 13 | Wscript.Echo "UserName: " & objItem.UserName 14 | Next 15 | End Sub -------------------------------------------------------------------------------- /vbs/playground/functions/CheckRam.txt: -------------------------------------------------------------------------------- 1 | Function CheckRam(strComputer) 2 | ' 3 | ' Returns the amount of installed RAM 4 | ' 5 | Dim objWMIService 6 | Dim colItems 7 | Dim objItem 8 | Dim intClientRAM 9 | 10 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 11 | Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem",,48) 12 | 13 | For Each objItem in colItems 14 | intClientRam = Cdbl(objItem.TotalPhysicalMemory /1024 /1024 /1024 ) 15 | Next 16 | 17 | CheckRam = intClientRAM 18 | End Function 19 | -------------------------------------------------------------------------------- /powershell/playground/PaperCutlogging.ps1: -------------------------------------------------------------------------------- 1 | # Read in papercut log file minus line 1 2 | $plog = Get-Content .\papercut-print-log-2011-04-03.csv | Select-Object -Skip 1 3 | 4 | # Create a temp log file to use for import-csv 5 | Set-Content -path 'C:\Users\Jeff Patton\Desktop\temp.csv' -Value $plog 6 | 7 | # Parse the temp log into variable 8 | $plog = Import-Csv .\temp.csv 9 | 10 | # Display top print users 11 | $plog |Group-Object User |Sort-Object Count -Descending 12 | 13 | # Display top printers 14 | $plog |Group-Object Printer |Sort-Object Count -Descending 15 | 16 | -------------------------------------------------------------------------------- /vbs/playground/PrintLogs.vbs: -------------------------------------------------------------------------------- 1 | Call GetPrintLogs(".") 2 | 3 | Sub GetPrintLogs(strComputer) 4 | ' 5 | ' A function to return the number of processes 6 | ' running on the provided computer. 7 | ' 8 | 9 | Dim objWMIService 10 | Dim colItems 11 | Dim objItem 12 | 13 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 14 | Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NTLogEvent WHERE SourceName='Microsoft-Windows-PrintService'",,48) 15 | 16 | For Each objItem In colItems 17 | Wscript.Echo objItem 18 | Next 19 | End Sub -------------------------------------------------------------------------------- /vbs/playground/procedures/BuildReport.txt: -------------------------------------------------------------------------------- 1 | Sub BuildReport(strFileName, strFilePath) 2 | ' 3 | ' Create the output file 4 | ' 5 | Dim objFSO 6 | Dim strFile 7 | 8 | Set objFSO = CreateObject("Scripting.FileSystemObject") 9 | 10 | If (objFSO.FolderExists(strFilePath)) Then 11 | Set strFile = objFSO.CreateTextFile(strFilePath & "\" & strFileName , True) 12 | 13 | strFile.WriteLine("Data to be written") 14 | strFile.Close 15 | Else 16 | Call LogData(1, strFilePath & " doesn't exist exiting script.") 17 | Exit Sub 18 | End If 19 | 20 | End Sub -------------------------------------------------------------------------------- /powershell/playground/mlbImport.ps1: -------------------------------------------------------------------------------- 1 | param ( 2 | $Date = (Get-Date) 3 | ) 4 | 5 | $Today = (Get-Date) 6 | 7 | $startofmonth = Get-Date $Date -day 1 -hour 0 -minute 0 -second 0 8 | $endofmonth = (($startofmonth).AddMonths(1).AddSeconds(-1)) 9 | 10 | if ($Today.Month -eq (Get-Date $Date).Month) { 11 | for ($i = 1; $i -le ($Today.Day - 1); $i++) { 12 | .\mlbData.ps1 -Date "$($startofmonth.Month)-$($i)-$($startofmonth.Year)" 13 | } 14 | } 15 | else { 16 | for ($i = 1; $i -le $endofmonth.Day; $i++) { 17 | .\mlbData.ps1 -Date "$($startofmonth.Month)-$($i)-$($startofmonth.Year)" 18 | } 19 | } -------------------------------------------------------------------------------- /vbs/playground/procedures/ChangePass.txt: -------------------------------------------------------------------------------- 1 | Sub ChangePass(strComputer, strAccount, strPassword) 2 | ' 3 | ' http://www.microsoft.com/technet/scriptcenter/resources/qanda/jul07/hey0703.mspx 4 | ' 5 | ' Modified to make the procedure more generic so it will work in more than 6 | ' one scenario. 7 | ' 8 | Dim objUser 9 | 10 | Set objUser = GetObject("WinNT://" & strComputer & "/" & strAccount) 11 | objUser.SetPassword strPassword 12 | If Err <> 0 Then Call LogData(1, Err.Number & vbCrLf & Err.Description & vbCrLf & "Unable to add " & strDomainGroup & " to " & strLocalGroup) 13 | End Sub -------------------------------------------------------------------------------- /vbs/playground/procedures/ConnectPrinters.txt: -------------------------------------------------------------------------------- 1 | Sub ConnectPrinters(strPrintServer, strPrinter, bolDefault) 2 | Dim objNetwork 3 | 4 | On Error Resume Next 5 | Set objNetwork = CreateObject("Wscript.Network") 6 | 7 | objNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & strPrinter 8 | If Err <> 0 Then 9 | Call LogData(1, "Error Number: " & Err.Number & vbCrLf & "Error Description: " & err.Description) 10 | Err.Clear 11 | End If 12 | 13 | If bolDefault = vbTrue Then 14 | objNetwork.SetDefaultPrinter "\\" & strPrintServer & "\" & strPrinter 15 | End If 16 | End Sub -------------------------------------------------------------------------------- /vbs/playground/functions/CheckVariable.txt: -------------------------------------------------------------------------------- 1 | Function CheckVariable(strVarName) 2 | ' 3 | ' Returns True or False depending on whether the variable exists or not 4 | ' 5 | Dim objWMIService 6 | Dim colItems 7 | Dim objItem 8 | Dim blnFound 9 | 10 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") 11 | Set colItems = objWMIService.ExecQuery("Select * from Win32_Environment") 12 | 13 | For Each objItem in colItems 14 | If objItem.Name = strVarName Then 15 | blnFound = vbTrue 16 | End If 17 | Next 18 | 19 | CheckVariable = blnFound 20 | End Function -------------------------------------------------------------------------------- /powershell/playground/Start-GroupMaintenanceMode.ps1: -------------------------------------------------------------------------------- 1 | $GroupDisplayName = "Exchange Servers" 2 | 3 | Import-Module OperationsManager 4 | New-SCOMManagementGroupConnection -ComputerName $ScomServer 5 | 6 | $StartTime = [datetime]::Now.touniversaltime() 7 | $ScheduledEndTime = ([datetime]::Now).addminutes($DurationInMin).touniversaltime() 8 | 9 | ForEach ($Group in (Get-ScomGroup -DisplayName $GroupDisplayName)) 10 | { 11 | If ($group.InMaintenanceMode -eq $false) 12 | { 13 | $group.ScheduleMaintenanceMode($StartTime, $ScheduledEndTime, $Reason, $Comment, "Recursive") 14 | } 15 | } -------------------------------------------------------------------------------- /vbs/playground/functions/GetProp.txt: -------------------------------------------------------------------------------- 1 | Function GetProp(strADSPath, strProperty) 2 | On Error Resume Next 3 | ' 4 | ' Get the specified property from the requested AD object 5 | ' 6 | Dim objComputer 7 | Dim objProperty 8 | Dim strStatus 9 | 10 | Set objComputer = GetObject("LDAP://" & strADSPath) 11 | objProperty = objComputer.Get(strProperty) 12 | 13 | If IsNull(objProperty) Then 14 | Call LogData(2, "No '" & strProperty & "' found for: " & vbCrLf & strADSPath) 15 | Else 16 | strStatus = objProperty 17 | objProperty = Null 18 | End If 19 | 20 | GetProp = strStatus 21 | End Function -------------------------------------------------------------------------------- /vbs/production/adutils/GetProp.txt: -------------------------------------------------------------------------------- 1 | Function GetProp(strADSPath, strProperty) 2 | On Error Resume Next 3 | ' 4 | ' Get the specified property from the requested AD object 5 | ' 6 | Dim objComputer 7 | Dim objProperty 8 | Dim strStatus 9 | 10 | Set objComputer = GetObject("LDAP://" & strADSPath) 11 | objProperty = objComputer.Get(strProperty) 12 | 13 | If IsNull(objProperty) Then 14 | Call LogData(2, "No '" & strProperty & "' found for: " & vbCrLf & strADSPath) 15 | Else 16 | strStatus = objProperty 17 | objProperty = Null 18 | End If 19 | 20 | GetProp = strStatus 21 | End Function -------------------------------------------------------------------------------- /vbs/playground/procedures/DisconnectPrinters.txt: -------------------------------------------------------------------------------- 1 | Sub DisconnectPrinters 2 | ' Disconnect network printers 3 | ' 4 | ' http://www.microsoft.com/technet/scriptcenter/resources/qanda/nov07/hey1102.mspx 5 | ' 6 | Dim objWMIService 7 | Dim colInstalledPrinters 8 | Dim objPrinter 9 | 10 | On Error Resume Next 11 | Set objWMIService = GetObject("winmgmts:\\" & strComputerName & "\root\cimv2") 12 | Set colInstalledPrinters = objWMIService.ExecQuery("SELECT * FROM Win32_Printer WHERE Network = True") 13 | 14 | For Each objPrinter In colInstalledPrinters 15 | objPrinter.Delete_ 16 | Next 17 | 18 | End Sub -------------------------------------------------------------------------------- /vbs/playground/functions/CheckFreeSpace.txt: -------------------------------------------------------------------------------- 1 | Function CheckFreeSpace(strComputer, strDrive) 2 | ' 3 | ' Returns the amount of free space on the given drive in GB 4 | ' 5 | Dim objWMIService 6 | Dim colItems 7 | Dim objItem 8 | Dim intFreeSpace 9 | 10 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 11 | Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk WHERE Name = '" & strDrive &"'",,48) 12 | 13 | For Each objItem in colItems 14 | intFreeSpace = (((objItem.FreeSpace \1024)\1024)\1024) 15 | Next 16 | 17 | CheckFreeSPace = intFreeSpace 18 | End Function 19 | -------------------------------------------------------------------------------- /vbs/playground/functions/GetUser.txt: -------------------------------------------------------------------------------- 1 | Function GetUser(strComputer) 2 | ' 3 | ' Get username of currently logged on user 4 | ' 5 | Dim strUserName 6 | Dim objWMIService 7 | Dim colItems 8 | Dim objItem 9 | 10 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 11 | Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem",,48) 12 | 13 | For Each objItem in colItems 14 | If IsNull(objItem.UserName) Then 15 | strUserName = "FREE" 16 | Else 17 | strUserName = objItem.UserName 18 | End If 19 | Next 20 | 21 | GetUser = strUserName 22 | End Function -------------------------------------------------------------------------------- /vbs/playground/procedures/RegRead.txt: -------------------------------------------------------------------------------- 1 | Sub RegRead(strComputer, strKeyPath) 2 | On Error Resume Next 3 | ' 4 | ' This procedure reads the subkeys within a parent key 5 | ' 6 | ' http://msdn.microsoft.com/en-us/library/293bt9hh(VS.85).aspx 7 | ' 8 | Dim objRegistry 9 | Dim arrSubKeys 10 | Dim objSubKey 11 | 12 | Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv") 13 | 14 | objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys 15 | 16 | For Each objSubKey In arrSubKeys 17 | Call DelReg(strKeyPath & "\" & objSubKey) 18 | Next 19 | End Sub -------------------------------------------------------------------------------- /powershell/playground/Update-SCCMSources.ps1: -------------------------------------------------------------------------------- 1 | $SiteCode = "sms" 2 | $Source = "\\server1\APPS" 3 | $Destination = "\\server2\APPS" 4 | 5 | $Packages = Get-WMIObject -namespace "root\sms\site_$($SiteCode)" -class SMS_Package 6 | foreach ($Package in $Packages) 7 | { 8 | $Id = $Package.PackageID 9 | $ThisPackage = Get-WMIObject -namespace "root\sms\site_$($SiteCode)" -class SMS_Package -filter "PackageID=$($Id)" 10 | 11 | foreach ($Item in $ThisPackage) 12 | { 13 | $Path = $Item.PkgSourcePath.Replace($Source, $Destination) 14 | $Item.PkgSourcePath = $Path 15 | $Item.Put() 16 | } 17 | } -------------------------------------------------------------------------------- /vbs/playground/AD_Trust.vbs: -------------------------------------------------------------------------------- 1 | strComputer = "dc2.soecs.ku.edu" 2 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftActiveDirectory") 3 | Set colItems = objWMIService.ExecQuery( _ 4 | "SELECT * FROM Microsoft_DomainTrustStatus",,48) 5 | For Each objItem in colItems 6 | Wscript.Echo "-----------------------------------" 7 | Wscript.Echo "Microsoft_DomainTrustStatus instance" 8 | Wscript.Echo "-----------------------------------" 9 | Wscript.Echo "TrustedDCName: " & objItem.TrustedDCName 10 | Wscript.Echo "TrustedDomain: " & objItem.TrustedDomain 11 | Wscript.Echo "TrustIsOk: " & objItem.TrustIsOk 12 | Next -------------------------------------------------------------------------------- /vbs/playground/functions/AccountEnabled.txt: -------------------------------------------------------------------------------- 1 | Function AccountEnabled(strUserName, strComputer) 2 | ' 3 | ' This function returns True if the specified account is found and enabled. 4 | ' 5 | Dim locUsers 6 | Dim objUser 7 | Dim strUser 8 | 9 | Set locUsers = GetObject("WinNT://" & strComputer & "") 10 | locUsers.Filter = Array("user") 11 | 12 | For Each objUser In locUsers 13 | strUser = objUser.Name 14 | Select Case strUser 15 | Case strUserName 16 | AccountEnabled = vbFalse 17 | If objUser.AccountDisabled = 0 Then 18 | AccountEnabled = vbTrue 19 | End If 20 | Case Else 21 | End Select 22 | Next 23 | End Function -------------------------------------------------------------------------------- /vbs/playground/procedures/BuildOUs.txt: -------------------------------------------------------------------------------- 1 | Sub BuildOUs(strUrl) 2 | ' 3 | ' Parse URL into smaller URLs 4 | ' 5 | Dim strBaseUrl 6 | Dim strVLANUrl 7 | Dim strBuildingUrl 8 | Dim strRoomUrl 9 | 10 | strRoomUrl = strUrl 11 | Call DiscoverObjects(strRoomUrl) 12 | 13 | strBuildingUrl = Right(strRoomUrl, (Len(strRoomUrl) -Instr(strRoomUrl, ","))) 14 | Call DiscoverObjects(strBuildingUrl) 15 | 16 | strVLANUrl = Right(strBuildingUrl , (Len(strBuildingUrl) -Instr(strBuildingUrl, ","))) 17 | Call DiscoverObjects(strVLANUrl) 18 | 19 | strBaseUrl = Right(strVLANUrl , (Len(strVLANUrl) -Instr(strVLANUrl, ","))) 20 | Call DiscoverObjects(strBaseUrl) 21 | 22 | End Sub -------------------------------------------------------------------------------- /powershell/playground/clonevm.ps1: -------------------------------------------------------------------------------- 1 | $vm = Get-VM "" | Get-View 2 | $cloneName = "" 3 | $cloneFolder = $vm.parent 4 | $cloneSpec = new-object Vmware.Vim.VirtualMachineCloneSpec 5 | $cloneSpec.Location = new-object Vmware.Vim.VirtualMachineRelocateSpec # required 6 | $cloneSpec.Location.Pool = (get-cluster "somecluster" | get-resourcepool "Resources" | get-view).MoRef 7 | $cloneSpec.Location.Host = (get-vm "somevm" | get-vmhost | get-view).MoRef 8 | $cloneSpec.Location.Datastore = (get-datastore -vm "anothervm" | get-view).MoRef 9 | $cloneSpec.Location.Transform = [Vmware.Vim.VirtualMachineRelocateTransformation]::sparse 10 | $vm.CloneVM_Task( $cloneFolder, $cloneName, $cloneSpec ) -------------------------------------------------------------------------------- /vbs/playground/procedures/HandleError.txt: -------------------------------------------------------------------------------- 1 | Sub HandleError(intErr, strErrDescription) 2 | ' 3 | ' Handle errors with pleasant messages 4 | ' 5 | Select Case intErr 6 | Case 3709 7 | ' 8 | ' ODB Connection Error 9 | ' 10 | Call LogData(1, "Error Number: " & intErr & vbCrLf & "Error Desc : " & strDescription & vbCrLf & "Defined : The proper ODBC driver is not present on this system.") 11 | Wscript.Quit 12 | Case Else 13 | Call LogData(1, "Error Number: " & intErr & vbCrLf & "Error Desc : " & strDescription & vbCrLf & "Defined : I have not yet seen this error number please submit a ticket at http://code.patton-tech.com/winmon.") 14 | End Select 15 | End Sub 16 | -------------------------------------------------------------------------------- /vbs/playground/wmi.vbs: -------------------------------------------------------------------------------- 1 | Wscript.Echo GetRunningProcesses(".") 2 | Function GetRunningProcesses(strComputer) 3 | ' 4 | ' A function to return the number of processes 5 | ' running on the provided computer. 6 | ' 7 | 8 | Dim objWMIService 9 | Dim colItems 10 | Dim objItem 11 | Dim intProcesses 12 | 13 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 14 | Set colItems = objWMIService.ExecQuery("SELECT Processes FROM Win32_PerfFormattedData_PerfOS_System",,48) 15 | 16 | For Each objItem In colItems 17 | intProcesses = objItem.Processes 18 | Next 19 | 20 | GetRunningProcesses = intProcesses 21 | End Function -------------------------------------------------------------------------------- /vbs/playground/functions/ListConnections.txt: -------------------------------------------------------------------------------- 1 | Function UserConnections(strComputer, strShare) 2 | ' 3 | ' This function connects to the remost server and counts the number 4 | ' of users connected to the provided share. 5 | ' 6 | Dim objWMIService 7 | Dim objItem 8 | Dim colItems 9 | Dim intCount 10 | 11 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 12 | Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ServerConnection",,48) 13 | 14 | For Each objItem in colItems 15 | If objItem.ShareName <> strShare Then 16 | Else 17 | intCount = intCount + 1 18 | End If 19 | 20 | Next 21 | 22 | UserConnections = intCount 23 | End Function -------------------------------------------------------------------------------- /vbs/playground/functions/GetMac.txt: -------------------------------------------------------------------------------- 1 | Function GetMac(strComputer, strSubNet) 2 | ' 3 | ' Get MAC Address of the computer 4 | ' 5 | Dim strMacAddress 6 | Dim objWMIService 7 | Dim colItems 8 | Dim objItem 9 | Dim strIPAddress 10 | 11 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 12 | Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration Where IPEnabled = True",,48) 13 | 14 | For Each objItem in colItems 15 | strIPAddress = Join(objItem.IPAddress, ",") 16 | If InStr(strIPAddress, strSubNet) Then 17 | strMacAddress = objItem.MACAddress 18 | Exit For 19 | End If 20 | Next 21 | 22 | GetMac = strMacAddress 23 | End Function -------------------------------------------------------------------------------- /vbs/playground/procedures/AddGroup.txt: -------------------------------------------------------------------------------- 1 | Sub AddGroup(strComputer, strLocalGroup, strDomainGroup, strDomain) 2 | ' 3 | ' http://www.microsoft.com/technet/scriptcenter/resources/qanda/jan08/hey0104.mspx 4 | ' 5 | ' Modified to make the procedure more generic so it will work in more than 6 | ' one scenario. 7 | ' 8 | Dim objLocalGroup 9 | Dim objADGroup 10 | 11 | Set objLocalGroup = GetObject("WinNT://" & strComputer & "/" & strLocalGroup) 12 | Set objADGroup = GetObject("WinNT://" & strDomain & "/" & strDomainGroup) 13 | 14 | objLocalGroup.Add(objADGroup.ADsPath) 15 | If Err <> 0 Then Call LogData(1, Err.Number & vbCrLf & Err.Description & vbCrLf & "Unable to add " & strDomainGroup & " to " & strLocalGroup) 16 | End Sub -------------------------------------------------------------------------------- /vbs/playground/procedures/RegDel.txt: -------------------------------------------------------------------------------- 1 | Sub RegDel(strRegistryKey) 2 | On Error Resume Next 3 | ' 4 | ' This procedure deletes a registry out of the Windows registry 5 | ' 6 | ' http://msdn.microsoft.com/en-us/library/293bt9hh(VS.85).aspx 7 | ' 8 | Dim objRegistry 9 | 10 | Set objRegistry=GetObject("winmgmts:\\.\root\default:StdRegProv") 11 | 12 | objRegistry.DeleteKey HKEY_LOCAL_MACHINE, strRegistryKey 13 | If Err <> 0 Then 14 | Call LogData(1, "Unable to delete the following registry key: " & vbCrLf & strRegistryKey & vbCrLf & Err.Number & vbCrLf & Err.Description) 15 | Err.Clear 16 | Else 17 | call Logdata(0, "Deleted the following registry key: " & vbCrLf & strRegistryKey) 18 | End If 19 | End Sub -------------------------------------------------------------------------------- /vbs/playground/user.vbs: -------------------------------------------------------------------------------- 1 | 2 | Wscript.Echo RetrieveUser 3 | 4 | ' Retrieve User 5 | ' 6 | ' http://www.microsoft.com/technet/scriptcenter/scripts/default.mspx?mfr=true 7 | ' http://www.microsoft.com/technet/scriptcenter/resources/qanda/may05/hey0526.mspx 8 | ' 9 | Function RetrieveUser() 10 | Dim objWMIService 11 | Dim colItems 12 | Dim objItem 13 | Dim arrUser 14 | Dim strUser 15 | 16 | On Error Resume Next 17 | Set objWMIService = GetObject("winmgmts:\\.\root\cimv2") 18 | Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem") 19 | 20 | For Each objItem in colItems 21 | arrUser = Split(objItem.UserName, "\") 22 | strUser = arrUser(1) 23 | Next 24 | 25 | RetrieveUser = strUser 26 | 27 | End Function -------------------------------------------------------------------------------- /vbs/playground/ListVars.vbs: -------------------------------------------------------------------------------- 1 | 2 | 3 | Wscript.echo Now() 4 | Set objWMIService = GetObject("winmgmts:\\delete-me.soecs.ku.edu\root\cimv2") 5 | 6 | Set colItems = objWMIService.ExecQuery("Select * from Win32_Environment") ' Where Name = 'LM_LICENSE_FILE'") 7 | Wscript.echo "Query Executed" 8 | 9 | For Each objItem in colItems 10 | 11 | 12 | If objItem.Name = "LM_LICENSE_FILE" Then 13 | blnFound = vbTrue 14 | Wscript.echo "True " & objItem.Name 15 | Wscript.Echo objItem.VariableValue 16 | Wscript.echo objItem.username 17 | Exit For 18 | Else 19 | Wscript.echo "False " & objItem.Name 20 | Wscript.Echo objItem.VariableValue 21 | Wscript.echo objItem.username 22 | blnFound = vbFalse 23 | End If 24 | 25 | Next 26 | -------------------------------------------------------------------------------- /vbs/playground/functions/SID2User.txt: -------------------------------------------------------------------------------- 1 | Function SID2User(strSID) 2 | ' 3 | ' This function returns the username of a SID 4 | ' from the Foreign Security Principals OU in 5 | ' your domain. 6 | ' 7 | ' You need to specify the name of your DC 8 | ' 9 | ' Source: 10 | ' http://blog.lazyindustries.com/?p=188 11 | ' 12 | Dim strComputer 13 | Dim objWMIService 14 | Dim objAccount 15 | 16 | strComputer = "dc1.soecs.ku.edu" 17 | set objWMIService=GetObject("winmgmts://" & strComputer & "/root/cimv2") 18 | set objAccount = objWMIService.Get("Win32_SID.SID='" & strSID & "'") 19 | 20 | If objAccount.AccountName = "" Then 21 | Else 22 | SID2User = objAccount.ReferencedDomainName & "\" & objAccount.AccountName 23 | End If 24 | End Function -------------------------------------------------------------------------------- /powershell/playground/simple-profile.ps1: -------------------------------------------------------------------------------- 1 | $Global:Admin="$" 2 | $CurrentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent() 3 | $principal = new-object System.Security.principal.windowsprincipal($CurrentUser) 4 | if ($principal.IsInRole("Administrators")) 5 | { 6 | $Admin="#" 7 | } 8 | 9 | # 10 | # Setup my custom prompt 11 | # 12 | Function prompt 13 | { 14 | $Now = $(get-date).Tostring("HH:mm:ss | MM-dd-yyy") 15 | "# $env:username@$env:computername | $Now | $(Get-Location) $Admin `n" 16 | } 17 | if ($Host.Name -eq 'ConsoleHost') 18 | { 19 | # 20 | # Set default editor 21 | # 22 | $Global:POSHEditor = 'c:\windows\notepad.exe' 23 | 24 | # 25 | # Start transcription 26 | # 27 | Start-Transcript 28 | } 29 | -------------------------------------------------------------------------------- /vbs/playground/ListComputers.vbs: -------------------------------------------------------------------------------- 1 | Const ADS_SCOPE_SUBTREE = 2 2 | Set objConnection = CreateObject("ADODB.Connection") 3 | Set objCommand = CreateObject("ADODB.Command") 4 | objConnection.Provider = "ADsDSOObject" 5 | objConnection.Open "Active Directory Provider" 6 | 7 | Set objCOmmand.ActiveConnection = objConnection 8 | objCommand.CommandText = "Select DistinguishedName ,Name from 'LDAP://DC=company,DC=com' Where objectClass='computer'" 9 | objCommand.Properties("Page Size") = 1000 10 | objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 11 | Set objRecordSet = objCommand.Execute 12 | objRecordSet.MoveFirst 13 | 14 | Do 15 | Wscript.Echo objRecordSet.Fields("Name").Value 16 | Wscript.Echo objRecordSet.Fields("Operating-System").Value 17 | objRecordSet.MoveNext 18 | Loop Until objRecordSet.EOF -------------------------------------------------------------------------------- /vbs/playground/printjobs.vbs: -------------------------------------------------------------------------------- 1 | Dim strComputer 2 | Dim strMessage 3 | Dim arrCol(5) 4 | Dim arrMessage(5) 5 | Dim strWhat 6 | Dim strWho 7 | Dim strWhere 8 | Dim intHowMany 9 | 10 | Set RegularExpressionObject = New RegExp 11 | 12 | strComputer = "." 13 | 14 | Set objWMIService = GetObject("winmgmts:" _ 15 | & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 16 | 17 | Set colLoggedEvents = objWMIService.ExecQuery("Select * from Win32_NTLogEvent Where Logfile = 'System' and EventCode = '10'") 18 | 19 | For Each objEvent in colLoggedEvents 20 | ' wscript.echo objEvent.Message 21 | 22 | 23 | Wscript.Echo "Record Number: " & objEvent.RecordNumber 24 | ' Wscript.Echo "Time Written: " & objEvent.TimeWritten 25 | ' Wscript.Echo "User: " & objEvent.User 26 | 'wscript.quit 27 | Next 28 | 29 | -------------------------------------------------------------------------------- /vbs/production/wmiutils/ListPrinters.txt: -------------------------------------------------------------------------------- 1 | Sub ListPrinters(strComputerName) 2 | ' List mapped printers 3 | ' 4 | ' http://www.microsoft.com/technet/scriptcenter/resources/qanda/nov07/hey1102.mspx 5 | ' 6 | Dim objWMIService 7 | Dim colInstalledPrinters 8 | Dim objPrinter 9 | 10 | On Error Resume Next 11 | Set objWMIService = GetObject("winmgmts:\\" & strComputerName & "\root\CIMV2") 12 | If Err <> 0 Then Call LogData(1, Err.Number & vbCrLf & Err.Description & vbCrLf & "Unable to connect to WMI service on remote computer") 13 | Set colInstalledPrinters = objWMIService.ExecQuery("SELECT * FROM Win32_Printer WHERE Local = False",,48) 14 | If Err <> 0 Then Call LogData(1, Err.Number & vbCrLf & Err.Description) 15 | 16 | For Each objPrinter In colInstalledPrinters 17 | Wscript.Echo objPrinter.Name 18 | Next 19 | 20 | End Sub -------------------------------------------------------------------------------- /vbs/production/wmiutils/ManageServices.txt: -------------------------------------------------------------------------------- 1 | Sub ManageServices(strComputer, strServiceName, strAction) 2 | ' 3 | ' This procedure uses WMI to connect to a computer and then based 4 | ' on strAction, either stop or start the provided service name. 5 | ' 6 | ' December 6, 2010 Jeff Patton 7 | ' 8 | Dim objWMIService 9 | Dim colListOfServices 10 | Dim objService 11 | 12 | Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\CIMV2") 13 | Set colListOfServices = objWMIService.ExecQuery("SELECT * FROM Win32_Service WHERE Name = '" & strServiceName & "'") 14 | 15 | For Each objService In colListOfServices 16 | Select Case LCase(strServiceName) 17 | Case "start" 18 | objService.StartService() 19 | Case "stop" 20 | objService.StopService() 21 | Case Else 22 | End Select 23 | End Sub -------------------------------------------------------------------------------- /vbs/playground/procedures/RemoteAddVar.txt: -------------------------------------------------------------------------------- 1 | Sub RemoteAddVar(strVariable, strVariableValue, strComputerName) 2 | ' 3 | ' http://msdn.microsoft.com/en-us/library/aa393600(VS.85).aspx 4 | ' 5 | CONST HKEY_LOCAL_MACHINE = &H80000002 6 | Dim objRegistry 7 | Dim strPath 8 | 9 | On Error Resume Next 10 | 11 | Set ObjRegistry = GetObject("winmgmts:{impersonationLevel = impersonate}!\\" & strComputerName & "\root\default:StdRegProv") 12 | 13 | strPath = "SYSTEM\CurrentControlSet\Control\Session Manager\Environment\" 14 | 15 | objRegistry.SetStringValue HKEY_LOCAL_MACHINE, strPath, strVariable, strVariableValue 16 | If Err <> 0 Then 17 | Call LogData(1, strComputerName & vbCrLf & Err.Number & vbCrLf & Err.Description) 18 | Err.Clear 19 | Else 20 | Call LogData(0, "Successfully updated the registry on: " & strComputerName) 21 | End If 22 | End Sub -------------------------------------------------------------------------------- /vbs/playground/functions/NT4toDN.txt: -------------------------------------------------------------------------------- 1 | Function NT4toDN(strUsername) 2 | ' 3 | ' This function accepts a username in the form of 4 | ' DOMAIN\User 5 | ' It then converts that name to a DN 6 | ' CN=User,OU=users,DC=company,DC=com 7 | ' 8 | ' Source: Technet 9 | ' http://blogs.technet.microsoft.com/b/heyscriptingguy/archive/2007/08/22/how-can-i-get-the-guid-for-a-user-account-if-all-i-have-is-the-user-s-logon-name-and-domain.aspx 10 | ' 11 | 12 | Const ADS_NAME_INITTYPE_GC = 3 13 | Const ADS_NAME_TYPE_NT4 = 3 14 | Const ADS_NAME_TYPE_1779 = 1 15 | 16 | Set objTranslator = CreateObject("NameTranslate") 17 | 18 | objTranslator.Init ADS_NAME_INITTYPE_GC, "" ' You can set a gc or domainname here 19 | objTranslator.Set ADS_NAME_TYPE_NT4, strUsername 20 | 21 | strUserDN = objTranslator.Get(ADS_NAME_TYPE_1779) 22 | 23 | NT4toDN = strUserDN 24 | End Function -------------------------------------------------------------------------------- /vbs/production/adutils/NT4toDN.txt: -------------------------------------------------------------------------------- 1 | Function NT4toDN(strUsername) 2 | ' 3 | ' This function accepts a username in the form of 4 | ' DOMAIN\User 5 | ' It then converts that name to a DN 6 | ' CN=User,OU=users,DC=company,DC=com 7 | ' 8 | ' Source: Technet 9 | ' http://blogs.technet.microsoft.com/b/heyscriptingguy/archive/2007/08/22/how-can-i-get-the-guid-for-a-user-account-if-all-i-have-is-the-user-s-logon-name-and-domain.aspx 10 | ' 11 | 12 | Const ADS_NAME_INITTYPE_GC = 3 13 | Const ADS_NAME_TYPE_NT4 = 3 14 | Const ADS_NAME_TYPE_1779 = 1 15 | 16 | Set objTranslator = CreateObject("NameTranslate") 17 | 18 | objTranslator.Init ADS_NAME_INITTYPE_GC, "" ' You can set a gc or domainname here 19 | objTranslator.Set ADS_NAME_TYPE_NT4, strUsername 20 | 21 | strUserDN = objTranslator.Get(ADS_NAME_TYPE_1779) 22 | 23 | NT4toDN = strUserDN 24 | End Function -------------------------------------------------------------------------------- /vbs/production/utils/ping.txt: -------------------------------------------------------------------------------- 1 | Function PingHost(strHost) 2 | Dim objShell 3 | Dim objExec 4 | Dim strPingResult 5 | 6 | Set objShell = CreateObject("Wscript.Shell") 7 | Set objExec = objShell.Exec("ping -n 2 -w 1000 " & strHost) 8 | strPingResult = LCase(objExec.StdOut.ReadAll) 9 | 10 | If InStr(strPingResult, "reply from") Then 11 | PingHost = "Online" 12 | Else 13 | PingHost = "Offline" 14 | End If 15 | End Function 16 | 17 | Function WMIPing(strComputer) 18 | ' 19 | ' Is computer online? 20 | ' 21 | ' Attempt WMI Connection if it fails ComputerOnline = False 22 | ' 23 | Dim blnOnline 24 | Dim objWMIService 25 | 26 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 27 | If Err <> 0 Then 28 | blnOnline = vbFalse 29 | Else 30 | blnOnline = vbTrue 31 | End If 32 | 33 | ComputerOnline = blnOnline 34 | End Function 35 | -------------------------------------------------------------------------------- /vbs/playground/procedures/DrivesByGroup.txt: -------------------------------------------------------------------------------- 1 | Sub DrivesByGroup 2 | ' 3 | ' This procedure maps drives based on group membership 4 | ' 5 | Dim objADSysInfo 6 | Dim strUser 7 | Dim objUser 8 | Dim colGroups 9 | Dim objGroup 10 | 11 | Set objADSysInfo = CreateObject("ADSystemInfo") 12 | strUser = objADSysInfo.UserName 13 | 14 | Set objUser = GetObject("LDAP://" & strUser) 15 | 16 | Set colGroups = objUser.Groups 17 | For Each objGroup in colGroups 18 | Select Case objGroup.CN 19 | Case "Group One" 20 | Call ConnectDrives("W:", "files.domain.com", "Share One", "") 21 | Case "Group Two" 22 | Call ConnectDrives("S:", "files.domain.com", "Share Two", "") 23 | Case "Group Three" 24 | Call ConnectDrives("S:", "files.domain.com", "Share Two", "") 25 | Case Else 26 | Call LogData(2, "No drive mapping for group: " & objGroup.CN) 27 | End Select 28 | 29 | Next 30 | End Sub -------------------------------------------------------------------------------- /vbs/playground/WMIFilter.vbs: -------------------------------------------------------------------------------- 1 | ' 2 | ' This function returns false when run on a notebook or true on a desktop 3 | ' 4 | ' In order to prevent a GPO from being applied the filter should return false 5 | ' 6 | ' http://technet.microsoft.com/en-us/library/cc779036.aspx 7 | ' 8 | ' Created February 4, 2009: Jeff Patton 9 | ' 10 | Dim objWMIService 11 | Dim colItems 12 | Dim objItem 13 | Dim bolDesktop 14 | 15 | Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2") 16 | Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_SystemEnclosure",,48) 17 | 18 | For Each objItem in colItems 19 | If isNull(objItem.ChassisTypes) Then 20 | Wscript.Echo strComputer 21 | Else 22 | Select Case Join(objItem.ChassisTypes, ",") 23 | Case 8, 9, 10, 11, 12 24 | bolDesktop = vbFalse 25 | Case Else 26 | bolDesktop = vbTrue 27 | End Select 28 | End If 29 | Next 30 | 31 | Wscript.Echo bolDesktop -------------------------------------------------------------------------------- /powershell/playground/Get-logs.ps1: -------------------------------------------------------------------------------- 1 | . ..\production\includes\FileManagement.ps1 2 | 3 | $IISLog = Get-WebLogs -LogFile 'C:\Users\Jeff Patton\Desktop\u_ex110418.log' -LogType iis 4 | $ApacheLog = Get-WebLogs -LogFile 'C:\Users\Jeff Patton\Desktop\scripts_access.log' -LogType apache 5 | 6 | # Displays a sorted list of visitors 7 | $ApacheLog | Sort-Object RemoteHost | Group-Object RemoteHost | Sort-Object Count -Descending 8 | 9 | # Displays a sorted list of httpd status codes 10 | $ApacheLog | Sort-Object Status | Group-Object Status | Sort-Object Count -Descending 11 | $ApacheLog |Select-Object RemoteHost, Time, Request, Status |Where-Object {$_.Status -eq 404} 12 | $ApacheLog |Where-Object {$_.RemoteHost -notlike "66.249.*"} |Group-Object RemoteHost |Sort-Object Count -Descending 13 | 14 | 15 | # Displays a list of http status codes 16 | $IISLog |Where-Object {$_.ProtocolStatus -eq 404} |Select-Object ClientIP, URIStem, URIQuery |Format-Table -------------------------------------------------------------------------------- /vbs/playground/ports.vbs: -------------------------------------------------------------------------------- 1 | 'strComputer = "." 2 | 3 | 'Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 4 | 'Set colPorts = objWMIService.ExecQuery("Select * from Win32_TCPIPPrinterPort") 5 | 6 | ' Wscript.Echo "@ echo off" 7 | ' Wscript.Echo "ipconfig /flushdns" 8 | 9 | 'For Each objPort in colPorts 10 | ' Wscript.Echo "Date /T" 11 | ' Wscript.Echo "Time /T" 12 | ' Wscript.Echo "nslookup " & objPort.Name 13 | ' Wscript.Echo "ping -n 1 " & objPort.Name 14 | 15 | ' Wscript.Echo objPort.SystemName 16 | ' Wscript.Echo objPort.Name 17 | 'Next 18 | 19 | strComputer = "." 20 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 21 | Set colItems = objWMIService.ExecQuery( _ 22 | "SELECT * FROM Win32_Printer",,48) 23 | For Each objItem in colItems 24 | Wscript.Echo "Name: " & objItem.Name 25 | Wscript.Echo "PortName: " & objItem.PortName 26 | Next -------------------------------------------------------------------------------- /vbs/playground/procedures/ClearFolder.txt: -------------------------------------------------------------------------------- 1 | Sub ClearFolder(strPath) 2 | ' Delete files in a folder 3 | ' 4 | ' http://www.microsoft.com/technet/scriptcenter/scripts/storage/files/stfivb06.mspx 5 | ' http://www.microsoft.com/technet/scriptcenter/scripts/storage/folders/stfovb29.mspx 6 | ' 7 | On Error Resume Next 8 | Dim blnDeleteReadOnly 9 | Dim objFSO 10 | 11 | blnDeleteReadOnly = True 12 | Set objFSO = CreateObject("Scripting.FileSystemObject") 13 | 14 | If objFSO.FolderExists(strPath) Then 15 | objFSO.DeleteFile(strPath & "\*.*"), blnDeleteReadOnly 16 | If Err <> 0 Then 17 | Call LogData(1, "Unable to delete: '" & strPath & vbCrLf & "'" & "Error Number: " & vbTab & Err.Number & vbCrLf & "Error Description: " & vbTab & Err.Description) 18 | Err.Clear 19 | Exit Sub 20 | End If 21 | Call LogData(0, "Successfully deleted: '" & strPath & "'") 22 | Else 23 | Call LogData(1, strPath & " does not exist.") 24 | End If 25 | End Sub -------------------------------------------------------------------------------- /vbs/production/MklinkhomeDirectory.vbs: -------------------------------------------------------------------------------- 1 | ' 2 | ' MKLink homeDirectory 3 | ' 4 | ' March 2, 2011: Jeff Patton 5 | ' 6 | ' This script reads in the username of the user running this script 7 | ' and the current location of the user's desktop. It takes that 8 | ' information and uses MKLINK to create a symlink on their desktop 9 | ' to the shared storage location specifed in ther user object. 10 | ' 11 | ' If the user doesn't have a homeDirectory specified then exit. 12 | ' 13 | 14 | Set adSysInfo = CreateObject("ADSystemInfo") 15 | Set CurrentUser = GetObject("LDAP://"& ADSysInfo.UserName) 16 | set WshShell = WScript.CreateObject("WScript.Shell") 17 | 18 | strLinkFolder = "Link" 19 | strCommand = "mklink /d " & chr(34) & WshShell.SpecialFolders("Desktop") & "\" & strLinkFolder & chr(34) & " " & chr(34) & CurrentUser.homeDirectory & chr(34) 20 | wscript.echo strCommand 21 | If IsEmpty(CurrentUser.homeDirectory) Then Wscript.Quit 22 | RunCommand = WshShell.Run("cmd.exe /c " & strCommand,1,vbTrue) -------------------------------------------------------------------------------- /vbs/production/adutils/WriteData.vbs: -------------------------------------------------------------------------------- 1 | 'call writedata("serialNumber","15YQMN1", "CN=e1005-pc45,OU=1005,OU=Eaton,OU=Labs,DC=soecs,DC=ku,DC=edu") 2 | 'call writedata("ipHostNumber","10.133.0.117", "CN=e1005-pc45,OU=1005,OU=Eaton,OU=Labs,DC=soecs,DC=ku,DC=edu") 3 | 'call writedata("macAddress","AA:BB:CC:DD:EE:FF", "CN=e1005-pc45,OU=1005,OU=Eaton,OU=Labs,DC=soecs,DC=ku,DC=edu") 4 | Set objOU = GetObject("LDAP://CN=e1005-pc45,OU=1005,OU=Eaton,OU=Labs,DC=soecs,DC=ku,DC=edu") 5 | Wscript.Echo objOU.Get("Name") 6 | Wscript.Echo objOU.Get("description") 7 | Wscript.Echo objOU.Get("macAddress") 8 | Wscript.Echo objOU.Get("serialNumber") 9 | 10 | Sub WriteData(strProperty, strValue, strADSPath) 11 | ' 12 | ' Update a single-value property of an object in AD 13 | ' 14 | Dim objADObject 15 | 16 | Set objADObject = GetObject("LDAP://" & strADSPath) 17 | 18 | objADObject.Put strProperty , strValue 19 | 'objADObject.PutEx 3, strProperty, Array(strValue) 20 | objADObject.SetInfo 21 | 22 | End Sub 23 | -------------------------------------------------------------------------------- /vbs/playground/dbtest.vbs: -------------------------------------------------------------------------------- 1 | 2 | Const adOpenStatic = 3 3 | Const adLockOptimistic = 3 4 | Const adUseClient = 3 5 | Set objConnection = CreateObject("ADODB.Connection") 6 | Set objRecordset = CreateObject("ADODB.Recordset") 7 | objConnection.Open "DSN=Inventory;" 8 | objRecordset.CursorLocation = adUseClient 9 | objRecordset.Open "SELECT * FROM Hardware" , objConnection, _ 10 | adOpenStatic, adLockOptimistic 11 | strComputer = "." 12 | Set objWMIService = GetObject("winmgmts:" _ 13 | & "{impersonationLevel=impersonate}!\\" & strComputer& "\root\cimv2") 14 | Set colSoundCards = objWMIService.ExecQuery _ 15 | ("SELECT * FROM Win32_SoundDevice") 16 | For Each objSoundCard in colSoundCards 17 | objRecordset.AddNew 18 | objRecordset("ComputerName") = objSoundCard.SystemName 19 | objRecordset("Manufacturer") = objSoundCard.Manufacturer 20 | objRecordset("ProductName") = objSoundCard.ProductName 21 | objRecordset.Update 22 | Next 23 | objRecordset.Close 24 | objConnection.Close 25 | -------------------------------------------------------------------------------- /powershell/production/vcheck/ad-plugins/00 GetLibrary.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | If you would like to have access to the full AD library I have written 3 | please set $Global:LoadLibFromURL = $true. 4 | 5 | Otherwise this updated file will dot-source the stub library that 6 | has only the functions required for the plug-in to work. 7 | #> 8 | $Title = "Library Settings for AD-Plugins" 9 | $Comments = "Define how to grab functions" 10 | $Display = "List" 11 | $Author = "Jeff Patton" 12 | $PluginVersion = 1 13 | 14 | $Global:LoadLibFromURL = $false 15 | 16 | if ($LoadLibFromURL -eq $false) 17 | { 18 | . .\Plugins\ADStubLibrary.ps1 19 | } 20 | else 21 | { 22 | $LibFile = (Join-Path $pwd "ActiveDirectoryManagement.ps1") 23 | $LibURL = "http://mod-posh.googlecode.com/svn/powershell/production/includes/ActiveDirectoryManagement.ps1" 24 | $webclient = New-Object Net.Webclient 25 | $webClient.UseDefaultCredentials = $true 26 | $webClient.DownloadFile($LibURL, $LibFile) 27 | . $LibFile 28 | } -------------------------------------------------------------------------------- /vbs/production/wmiutils/SystemCenter.vbs: -------------------------------------------------------------------------------- 1 | Function SCCMPerformAction(sActionName, strComputerName) 2 | ' Available Actions in the Configuration Manager 3 | ' Properties Dialog, Action tab. 4 | ' 5 | ' "Software Inventory Collection Cycle" 6 | ' "MSI Product Source Update Cycle" 7 | ' "Hardware Inventory Collection Cycle" 8 | ' "Software Updates Assignments Evaluation Cycle" 9 | ' "Standard File Collection Cycle" 10 | ' "Discovery Data Collection Cycle" 11 | ' "Request & Evaluate User Policy" 12 | ' "Peer DP Maintenance Task" 13 | ' "Request & Evaluate Machine Policy" 14 | ' "Software Metering Usage Report Cycle" 15 | Dim oCPAppletMgr 16 | Dim oClientActions 17 | Dim oClientAction 18 | 19 | Set oCPAppletMgr = CreateObject("CPApplet.CPAppletMgr", strComputerName) 20 | Set oClientActions = oCPAppletMgr.GetClientActions() 21 | For Each oClientAction In oClientActions 22 | If oClientAction.Name = sActionName Then 23 | SCCMPerformAction = oClientAction.PerformAction 24 | End If 25 | Next 26 | End Function -------------------------------------------------------------------------------- /vbs/production/adutils/QueryAD.txt: -------------------------------------------------------------------------------- 1 | Sub QueryAD(strQuery) 2 | On Error Resume Next 3 | ' 4 | ' This procedure will loop through a recordset of objects 5 | ' returned from a query. 6 | ' 7 | Const ADS_SCOPE_SUBTREE = 2 8 | Dim objConnection 9 | Dim objCommand 10 | Dim objRecordset 11 | 12 | Set objConnection = CreateObject("ADODB.Connection") 13 | Set objCommand = CreateObject("ADODB.Command") 14 | objConnection.Provider = "ADsDSOObject" 15 | objConnection.Open "Active Directory Provider" 16 | 17 | Set objCOmmand.ActiveConnection = objConnection 18 | objCommand.CommandText = strQuery 19 | objCommand.Properties("Page Size") = 1000 20 | objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 21 | Set objRecordSet = objCommand.Execute 22 | If Err <> 0 Then Call LogData(1, "Unable to connect using the provided query: " & vbCrLf & strQuery) 23 | 24 | objRecordSet.MoveFirst 25 | 26 | Do Until objRecordSet.EOF 27 | ' 28 | ' Code to do whatever is needed 29 | ' 30 | objRecordSet.MoveNext 31 | Loop 32 | End Sub -------------------------------------------------------------------------------- /vbs/playground/procedures/FixDupRegEntry.txt: -------------------------------------------------------------------------------- 1 | Sub FixDupRegEntry(strRegistry, strRegValue) 2 | ' Fix update service sid issue 3 | ' 4 | ' http://www.microsoft.com/technet/scriptcenter/guide/sas_wsh_oiuk.mspx 5 | ' 6 | ' Provide the registry key that might have the duplicate entry 7 | ' Provide the entry in question 8 | ' Provide the complete registry key to delete 9 | ' 10 | On Error Resume Next 11 | Dim objShell 12 | Dim strCurrentRegValue 13 | 14 | Set objShell = Wscript.CreateObject("Wscript.Shell") 15 | 16 | strCurrentRegValue = objShell.RegRead(strRegistry) 17 | 18 | If strCurrentRegValue = strRegValue Then 19 | Call LogData(1, "Found duplicate registry entry") 20 | objShell.RegDelete(strRegistry) 21 | If Err <> 0 Then 22 | Call LogData(1, "Error Number: " & vbTab & Err.Number & vbCrLf & "Error Description: " & vbTab & Err.Description) 23 | Err.Clear 24 | Exit Sub 25 | End If 26 | Call Logdata(0, "Deleted duplicate registry entry, client will show up on next reboot.") 27 | Else 28 | End If 29 | End Sub -------------------------------------------------------------------------------- /vbs/playground/procedures/QueryAD.txt: -------------------------------------------------------------------------------- 1 | Sub QueryAD(strQuery) 2 | On Error Resume Next 3 | ' 4 | ' This procedure will loop through a recordset of objects 5 | ' returned from a query. 6 | ' 7 | Const ADS_SCOPE_SUBTREE = 2 8 | Dim objConnection 9 | Dim objCommand 10 | Dim objRecordset 11 | 12 | Set objConnection = CreateObject("ADODB.Connection") 13 | Set objCommand = CreateObject("ADODB.Command") 14 | objConnection.Provider = "ADsDSOObject" 15 | objConnection.Open "Active Directory Provider" 16 | 17 | Set objCOmmand.ActiveConnection = objConnection 18 | objCommand.CommandText = strQuery 19 | objCommand.Properties("Page Size") = 1000 20 | objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 21 | Set objRecordSet = objCommand.Execute 22 | If Err <> 0 Then Call LogData(1, "Unable to connect using the provided query: " & vbCrLf & strQuery) 23 | 24 | objRecordSet.MoveFirst 25 | 26 | Do Until objRecordSet.EOF 27 | ' 28 | ' Code to do whatever is needed 29 | ' 30 | objRecordSet.MoveNext 31 | Loop 32 | End Sub -------------------------------------------------------------------------------- /vbs/playground/functions/ValidateHost.txt: -------------------------------------------------------------------------------- 1 | Function ValidateHost(strSearchField, strSearchFieldValue, dbServer, dbUser, dbPass, dbTable) 2 | ' 3 | ' This function returns the host_id if it finds a mac address 4 | ' 5 | Dim rs 6 | Dim strConnectString 7 | Dim strSQL 8 | Dim strField 9 | Dim strFoundField 10 | 11 | Set rs = CreateObject("ADODB.Recordset") 12 | 13 | strConnectString = "DRIVER={MySQL ODBC 5.1 Driver};Server=" & dbServer & ";UID=" & dbUser & ";Password=" & dbPass & ";Database=" & dbName & ";Option=3" 14 | rs.ActiveConnection = strConnectString 15 | strSQL = "Select id from " & dbTable & " WHERE " & strSearchField & " = '" & strSearchFieldValue & "';" 16 | rs.Open strSQL 17 | 18 | Do While Not rs.EOF 19 | for each strField in rs.Fields 20 | strFoundField = strField.Value 21 | Next 22 | rs.MoveNext 23 | Loop 24 | ' 25 | ' If we don't get a match, I believe this returns null 26 | ' so set it to 0. 27 | If isNull(strFoundField) Then 28 | strFoundField = 0 29 | End If 30 | 31 | ValidateHost = strFoundField 32 | End Function -------------------------------------------------------------------------------- /powershell/playground/Parse-AuditLogs.ps1: -------------------------------------------------------------------------------- 1 | Set-Location C:\Users\jspatton\Desktop\logs 2 | $Ids = '4775','4777','4662','5136','5137','5138','5139','5141','4625','4964','4675','5039','4659','4660','4661','4663','4771','4772','6273','6274','6275','6276','4715','4719','4817','4902','4904','4905','4906','4908','4912','4944','4945','4946','4947','4948','4949','4950','4951','4952','4953','4954','4956','4957','4958' 3 | 4 | foreach ($file in (Get-ChildItem -Filter *.evtx)) 5 | { 6 | $Seclog = Get-WinEvent -Path $file.FullName 7 | $oldCount = ($Seclog |Sort-Object -Property Id -Unique).Count 8 | $file.FullName 9 | $NewSeclog = @() 10 | foreach ($Id in $Ids) 11 | { 12 | $NewSeclog += $Seclog |Where-Object -Property Id -eq $Id 13 | } 14 | $newCount = ($NewSeclog |Sort-Object -Property Id -Unique).Count 15 | 16 | New-Object -TypeName PSobject -Property @{ 17 | LogFile = $File.Name 18 | IdCount = $oldCount 19 | AuditedCount = $newCount 20 | } 21 | Remove-Variable SecLog 22 | Remove-Variable NewSecLog 23 | } -------------------------------------------------------------------------------- /powershell/playground/Start-RSDataProcessing.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | http://www.techgraphs.com/building-a-retrosheet-database-part-1/ 3 | http://www.techgraphs.com/building-a-retrosheet-database-part-2/ 4 | 5 | #> 6 | [CmdletBinding()] 7 | Param 8 | ( 9 | ) 10 | Begin 11 | { 12 | Import-Module C:\retrosheet\common\powershell\RsModule.psm1; 13 | Get-RSDataFiles; 14 | } 15 | Process 16 | { 17 | $DataFiles = Get-ChildItem C:\retrosheet\data\unzipped -Filter "*.ev*"; 18 | Set-Location C:\retrosheet\data\unzipped; 19 | foreach ($DataFile in $DataFiles |ForEach-Object {$_.Name.Substring(0,4)} |Sort-Object -Unique) 20 | { 21 | $Year = $DataFile; 22 | $FileFilter = "$($DataFile)*.ev*"; 23 | Get-RSEvent -Year $Year -File $FileFilter -Verbose |Out-File "C:\Retrosheet\data\parsed\events\$($Year).csv"; 24 | Get-RSGame -Year $Year -File $FileFilter -Verbose |Out-File "C:\Retrosheet\data\parsed\games\$($Year).csv"; 25 | Get-RSSub -Year $Year -File $FileFilter -Verbose |Out-File "C:\Retrosheet\data\parsed\subs\$($Year).csv"; 26 | } 27 | } 28 | End 29 | { 30 | } -------------------------------------------------------------------------------- /vbs/playground/procedures/MapPrinters.txt: -------------------------------------------------------------------------------- 1 | Sub MapPrinter(strLDAPUrl,strPrintServer) 2 | ' 3 | ' Maps printer based on what OU the computer is in 4 | ' This works if the printer object has been moved into the OU 5 | ' 6 | ' Based on our naming convention, the default printer is a laser printer 7 | ' this information is pulled from the printer object itself. 8 | ' 9 | On Error Resume Next 10 | Dim objNetwork 11 | Dim objItem 12 | Dim colItems 13 | Dim strPrinter 14 | 15 | Set objNetwork = CreateObject("Wscript.Network") 16 | Set colItems = GetObject("LDAP://" & strLDAPUrl) 17 | 18 | For Each objItem in colItems 19 | If Left(objItem.CN, 3) = "PS-" Then 20 | strPrinter = Right(objItem.CN, Len(objItem.CN) - 3) 21 | If InStr(objItem.CN, "laser") Then 22 | objNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & strPrinter 23 | objNetwork.SetDefaultPrinter "\\" & strPrintServer & "\" & strPrinter 24 | Else 25 | objNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & strPrinter 26 | End If 27 | Else 28 | End If 29 | Next 30 | End Sub 31 | -------------------------------------------------------------------------------- /powershell/production/sample.ps1: -------------------------------------------------------------------------------- 1 | $PolicyFiles = Get-ChildItem \\home.ku.edu\SYSVOL\home.ku.edu\Policies -Filter "{*}" 2 | $Report = @() 3 | foreach ($PofilePath in $PolicyFiles) 4 | { 5 | $Guid = $PofilePath.Name.Replace('{','').Replace('}','') 6 | foreach ($File in (Get-ChildItem $PofilePath.FullName -Recurse)) 7 | { 8 | if ($File.Extension -eq ".xml") 9 | { 10 | if ($File.Name -eq 'groups.xml') 11 | { 12 | $groupFile = ([xml](Get-Content $File.fullname)).Groups.User.Properties 13 | if ($groupFile.cpassword) 14 | { 15 | $item = New-Object -TypeName PSobject -Property @{ 16 | GpoGuid = (Get-GPO -GpoID $Guid -Domain 'home.ku.edu').DisplayName 17 | username = $groupFile.username 18 | newname = $groupFile.newname 19 | cpassword = $groupFile.cpassword 20 | } 21 | } 22 | $Report += $Item 23 | } 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /vbs/playground/ListGroupAttributes.txt: -------------------------------------------------------------------------------- 1 | Set objGroupClass = GetObject("LDAP://schema/group") 2 | Set objSchemaClass = GetObject(objGroupClass.Parent) 3 | 4 | i = 0 5 | WScript.Echo "Mandatory attributes:" 6 | For Each strAttribute in objGroupClass.MandatoryProperties 7 | i= i + 1 8 | WScript.Echo i & vbTab & strAttribute 9 | Set objAttribute = objSchemaClass.GetObject("Property", strAttribute) 10 | WScript.Echo " (Syntax: " & objAttribute.Syntax & ")" 11 | If objAttribute.MultiValued Then 12 | WScript.Echo " Multivalued" 13 | Else 14 | WScript.Echo " Single-valued" 15 | End If 16 | Next 17 | 18 | WScript.Echo VbCrLf & "Optional attributes:" 19 | For Each strAttribute in objGroupClass.OptionalProperties 20 | i= i + 1 21 | Wscript.Echo i & vbTab & strAttribute 22 | Set objAttribute = objSchemaClass.GetObject("Property", strAttribute) 23 | Wscript.Echo " [Syntax: " & objAttribute.Syntax & "]" 24 | If objAttribute.MultiValued Then 25 | WScript.Echo " Multivalued" 26 | Else 27 | WScript.Echo " Single-valued" 28 | End If 29 | Next 30 | 31 | -------------------------------------------------------------------------------- /vbs/playground/inventory.vbs: -------------------------------------------------------------------------------- 1 | Set objFSO = CreateObject("Scripting.FileSystemObject") 2 | Set objFile = objFSO.CreateTextFile("C:\Documents and Settings\jeffpatton\My Documents\computers.txt") 3 | 'Set objFile = objFSO.OpenTextFile("C:\Documents and Settings\jeffpatton\My Documents\computers.txt", 2) 4 | 5 | Const ADS_SCOPE_SUBTREE = 2 6 | Set objConnection = CreateObject("ADODB.Connection") 7 | Set objCommand = CreateObject("ADODB.Command") 8 | objConnection.Provider = "ADsDSOObject" 9 | objConnection.Open "Active Directory Provider" 10 | Set objCommand.ActiveConnection = objConnection 11 | objCommand.CommandText = _ 12 | "SELECT Name, Location FROM 'LDAP://DC=company,DC=com' " _ 13 | & "WHERE objectClass='computer'" 14 | objCommand.Properties("Page Size") = 1000 15 | objCommand.Properties("Timeout") = 30 16 | objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 17 | objCommand.Properties("Cache Results") = False 18 | Set objRecordSet = objCommand.Execute 19 | objRecordSet.MoveFirst 20 | Do Until objRecordSet.EOF 21 | objFile.WriteLine ("Computer Name: " & objRecordSet.Fields("Name").Value) 22 | objRecordSet.MoveNext 23 | Loop 24 | objFile.Close -------------------------------------------------------------------------------- /powershell/playground/AzureSQLModule.ps1: -------------------------------------------------------------------------------- 1 | $Global:ConnectAzureSqlDatabase; 2 | 3 | function Connect-AzureSqlDatabase 4 | { 5 | [CmdletBinding()] 6 | param 7 | ( 8 | [pscredential]$SqlCredential, 9 | [string]$Servername, 10 | [string]$Database 11 | ) 12 | try 13 | { 14 | $ErrorActionPreference = 'Stop'; 15 | $Error.Clear(); 16 | 17 | $ConnectionString = "Server=tcp:$($Servername),1433;Initial Catalog=$Database;Persist Security Info=False;User ID=$($sqlCredential.Username);Password=$($SqlCredential.GetNetworkCredential().Password);MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"; 18 | $SqlConnectionStringBuilder = New-Object System.Data.SqlClient.SqlConnectionStringBuilder($ConnectionString); 19 | Write-Verbose $SqlConnectionStringBuilder.ConnectionString; 20 | $SqlConnection = New-Object System.Data.SqlClient.SqlConnection($SqlConnectionStringBuilder.ConnectionString); 21 | $Global:ConnectAzureSqlDatabase = $SqlConnection; 22 | $SqlConnection.Open(); 23 | } 24 | catch 25 | { 26 | throw $_; 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /vbs/playground/functions/GetIP.txt: -------------------------------------------------------------------------------- 1 | Function GetIP(strComputer, strSubNet, strMacAddress) 2 | On Error Resume Next 3 | ' 4 | ' Get IP Address of the computer 5 | ' 6 | Dim objWMIService 7 | Dim colItems 8 | Dim objItem 9 | Dim strIP 10 | Dim strIPAddress 11 | Dim IP 12 | 13 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 14 | If Err <> 0 Then 15 | Call HandleError(Err.Number, Err.Description) 16 | End If 17 | Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration Where IPEnabled = True",,48) 18 | If Err <> 0 Then 19 | Call HandleError(Err.Number, Err.Description) 20 | End If 21 | 22 | For Each objItem in colItems 23 | If objItem.MACAddress = strMACAddress Then 24 | strIPAddress = Join(objItem.IPAddress, ",") 25 | End If 26 | Next 27 | 28 | If InStr(strIPAddress, ",") Then 29 | strIPAddress = Split(strIPAddress, ",") 30 | For Each IP in strIPAddress 31 | If inStr(IP, strSubNet) Then 32 | strIP = IP 33 | Exit For 34 | End If 35 | next 36 | Else 37 | strIP = strIPAddress 38 | End If 39 | GetIP = strIP 40 | End Function 41 | -------------------------------------------------------------------------------- /vbs/playground/procedures/ListNetwork.txt: -------------------------------------------------------------------------------- 1 | Sub ListNetwork(strComputer) 2 | On Error Resume Next 3 | ' 4 | ' List the MAC and IP's of IP enabled Network Adapters 5 | ' 6 | Dim objWMIService 7 | Dim colItems 8 | Dim objItem 9 | Dim strIP 10 | Dim strIPAddress 11 | Dim strIPv4 12 | Dim strIPv6 13 | 14 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 15 | If Err <> 0 Then 16 | Call HandleError(Err.Number, Err.Description) 17 | End If 18 | Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration Where IPEnabled = True",,48) 19 | If Err <> 0 Then 20 | Call HandleError(Err.Number, Err.Description) 21 | End If 22 | 23 | For Each objItem in colItems 24 | strMac = objItem.MACAddress 25 | strIPAddress = objItem.IPAddress 26 | For Each strIP in strIPAddress 27 | If inStr(strIP, ".") Then 28 | strIPv4 = strIP 29 | End If 30 | If inStr(strIP, ":") Then 31 | strIPv6 = strIP 32 | End If 33 | Next 34 | Wscript.Echo "MAC: " & strMac 35 | Wscript.Echo "IP4: " & strIPv4 36 | Wscript.Echo "IP6: " & strIPv6 37 | 38 | Wscript.echo 39 | Next 40 | 41 | End Sub 42 | -------------------------------------------------------------------------------- /vbs/playground/drive.vbs: -------------------------------------------------------------------------------- 1 | Option Explicit 2 | 3 | Dim strISOFile 4 | 5 | If Wscript.Arguments.Count > 0 Then 6 | strISOFile = Wscript.Arguments.Item(0) 7 | Else 8 | Wscript.Echo "Invalid number of arguments" 9 | End If 10 | 11 | Call DetermineDrive 12 | 13 | Sub DetermineDrive 14 | On Error Resume Next 15 | 16 | Dim strComputer 17 | Dim objWMIService 18 | Dim colItems 19 | Dim objItem 20 | Dim strCapability 21 | Dim blnWriteable 22 | Dim strDriveLetter 23 | 24 | strComputer = "." 25 | Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 26 | 27 | Set colItems = objWMIService.ExecQuery("Select * from Win32_CDROMDrive") 28 | 29 | For Each objItem in colItems 30 | If objItem.Availability = 3 Then 31 | If objItem.MediaLoaded = vbTrue Then 32 | For Each strCapability in objItem.Capabilities 33 | If strCapability = 4 Then 34 | blnWriteable = vbTrue 35 | End If 36 | Next 37 | strDriveLetter = objItem.Drive 38 | Wscript.Echo "cdburn " & strDriveLetter & strISOFile 39 | Else 40 | Wscript.Echo "There is no media in drive " & objItem.Drive 41 | End If 42 | Else 43 | Wscript.Echo "The drive is offline." 44 | End If 45 | Next 46 | End Sub -------------------------------------------------------------------------------- /vbs/production/utils/Sendmail.txt: -------------------------------------------------------------------------------- 1 | Sub Sendmail(strFrom, strTo, strSub, strBody, strSmtpServer, blnAuthSmtp, strAuthUser, strAuthPass) 2 | ' 3 | ' A procedure that sends email 4 | ' http://technet.microsoft.com/en-us/library/ee176585.aspx 5 | ' 6 | Dim cdoAuthType 7 | 8 | cdoAuthType = 1 'Basic Auth 9 | 'cdoAuthType = 2 'NTLM Auth 10 | 11 | Set objEmail = CreateObject("CDO.Message") 12 | objEmail.From = strFrom 13 | objEmail.To = strTo 14 | objEmail.Subject = strSub 15 | objEmail.Textbody = strBody 16 | 17 | If blnAuth = vbTrue Then 18 | objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 19 | objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = strAuthUser 20 | objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = strAuthPass 21 | End If 22 | 23 | objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 24 | objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSmtpServer 25 | objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 26 | objEmail.Configuration.Fields.Update 27 | objEmail.Send 28 | End Sub -------------------------------------------------------------------------------- /vbs/playground/functions/ScriptDetails.txt: -------------------------------------------------------------------------------- 1 | Function ScriptDetails(strComputer) 2 | ' 3 | ' Return information about who, what, where 4 | ' 5 | On Error Resume Next 6 | Dim strScriptName 7 | Dim strScriptPath 8 | Dim strUserName 9 | Dim objWMIService 10 | Dim colProcesslist 11 | Dim objProcess 12 | Dim colProperties 13 | Dim strNameOfUser 14 | Dim struserDomain 15 | 16 | strScriptName = Wscript.ScriptName 17 | strScriptPath = Wscript.ScriptFullName 18 | 19 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") 20 | Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process Where Name = 'cscript.exe' or Name = 'wscript.exe'") 21 | 22 | For Each objProcess in colProcessList 23 | If InStr(objProcess.CommandLine, strScriptName) Then 24 | colProperties = objProcess.GetOwner(strNameOfUser,strUserDomain) 25 | If Err <> 0 Then 26 | Call LogData(1, "Error Number: " & vbTab & Err.Number & vbCrLf & "Error Description: " & vbTab & Err.Description) 27 | Err.Clear 28 | Exit For 29 | End If 30 | strUserName = strUserDomain & "\" & strNameOfUser 31 | End If 32 | Next 33 | 34 | ScriptDetails = "Script Name: " & strScriptName & vbCrLf & "Script Path: " & strScriptPath & vbCrLf & "Script User: " & strUserName 35 | End Function -------------------------------------------------------------------------------- /vbs/production/utils/ScriptDetails.txt: -------------------------------------------------------------------------------- 1 | Function ScriptDetails(strComputer) 2 | ' 3 | ' Return information about who, what, where 4 | ' 5 | On Error Resume Next 6 | Dim strScriptName 7 | Dim strScriptPath 8 | Dim strUserName 9 | Dim objWMIService 10 | Dim colProcesslist 11 | Dim objProcess 12 | Dim colProperties 13 | Dim strNameOfUser 14 | Dim struserDomain 15 | 16 | strScriptName = Wscript.ScriptName 17 | strScriptPath = Wscript.ScriptFullName 18 | 19 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") 20 | Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process Where Name = 'cscript.exe' or Name = 'wscript.exe'") 21 | 22 | For Each objProcess in colProcessList 23 | If InStr(objProcess.CommandLine, strScriptName) Then 24 | colProperties = objProcess.GetOwner(strNameOfUser,strUserDomain) 25 | If Err <> 0 Then 26 | Call LogData(1, "Error Number: " & vbTab & Err.Number & vbCrLf & "Error Description: " & vbTab & Err.Description) 27 | Err.Clear 28 | Exit For 29 | End If 30 | strUserName = strUserDomain & "\" & strNameOfUser 31 | End If 32 | Next 33 | 34 | ScriptDetails = "Script Name: " & strScriptName & vbCrLf & "Script Path: " & strScriptPath & vbCrLf & "Script User: " & strUserName 35 | End Function -------------------------------------------------------------------------------- /powershell/playground/createvm.ps1: -------------------------------------------------------------------------------- 1 | $HyperVServer = "it08082" 2 | $Vmname = "my-sample-vm1" 3 | $VhdName = "$($Vmname)-disk.vhd" 4 | [uint64]$VhdSize = 10 5 | [UInt64]$Size1G = 0x40000000 6 | 7 | $Vmpath = Get-WmiObject -Namespace 'root/virtualization' -Query "SELECT DefaultVirtualHardDiskPath FROM Msvm_VirtualSystemManagementServiceSettingData" 8 | $VmSwitch = Get-WmiObject -Namespace 'root/virtualization' -Query "SELECT ElementName FROM Msvm_VirtualSwitch" 9 | $VmService = Get-WmiObject -Namespace 'root/virtualization' -Query "SELECT * FROM Msvm_VirtualSystemManagementService" 10 | $ImageManagementService = Get-WmiObject -Namespace 'root\virtualization' -Class Msvm_ImageManagementService 11 | 12 | $GlobalSettingsData = ([WMIClass]"\\.\Root\Virtualization:MSVM_VirtualSystemGlobalSettingData").CreateInstance() 13 | $GlobalSettingsData.ElementName = $Vmname 14 | $GlobalSettingsData.ExternalDataRoot = $Vmpath 15 | 16 | $VmResult = $VmService.DefineVirtualSystem($GlobalSettingsData.GetText([System.Management.TextFormat]::WmiDtd20), $null, $null) 17 | 18 | $DiskResult = $ImageManagementService.CreateDynamicVirtualHardDisk("$($Vmpath.DefaultVirtualHardDiskPath)\$($VhdName)",$VhdSize * $Size1G) 19 | 20 | $NewVm = Get-WmiObject -Namespace 'root\virtualization' -Query "SELECT * FROM Msvm_ComputerSystem WHERE ElementName='$Vmname'" -------------------------------------------------------------------------------- /powershell/playground/Add-DomainGroupToLocalGroup.ps1: -------------------------------------------------------------------------------- 1 | Function Add-DomainGroupToLocalGroup 2 | { 3 | <# 4 | .SYNOPSIS 5 | Add a Domain security group to a local computer group 6 | .DESCRIPTION 7 | This function will add a Domain security group to a local computer group. 8 | .PARAMETER ComputerName 9 | The NetBIOS name of the computer to update 10 | .PARAMETER DomainGroup 11 | The name of the Domain security group 12 | .PARAMETER LocalGroup 13 | The name of the local group to update, if not provided Administrators is assumed. 14 | .PARAMETER UserDomain 15 | The NetBIOS domain name. 16 | .EXAMPLE 17 | .NOTES 18 | .LINK 19 | #> 20 | 21 | Param 22 | ( 23 | [Parameter(Mandatory=$true)] 24 | [string]$ComputerName, 25 | [Parameter(Mandatory=$true)] 26 | [string]$DomainGroup, 27 | [string]$LocalGroup="Administrators", 28 | [string]$UserDomain 29 | ) 30 | 31 | Begin 32 | { 33 | $ComputerObject = [ADSI]("WinNT://$($ComputerName),computer") 34 | $GroupObject = $ComputerObject.PSBase.Children.Find("$($LocalGroup)") 35 | } 36 | 37 | Process 38 | { 39 | $GroupObject.Add("WinNT://$UserDomain/$DomainGroup") 40 | } 41 | 42 | End 43 | { 44 | } 45 | } -------------------------------------------------------------------------------- /vbs/playground/Bios.vbs: -------------------------------------------------------------------------------- 1 | Const adOpenStatic = 3 2 | Const adLockOptimistic = 3 3 | Const adUseClient = 3 4 | Set objConnection = CreateObject("ADODB.Connection") 5 | Set objRecordset = CreateObject("ADODB.Recordset") 6 | Set objRecordset1 = CreateObject("ADODB.Recordset") 7 | objConnection.Open "DSN=NetworkInventory;" 8 | objRecordset.CursorLocation = adUseClient 9 | objRecordset.Open "SELECT * FROM Computers where computername='SOECS-ST-PATTON'" , objConnection, adOpenStatic, adLockOptimistic 10 | 11 | objRecordset1.Open "SELECT * FROM BIOS" , objConnection, adOpenStatic, adLockOptimistic 12 | 13 | objRecordSet.MoveFirst 14 | Do While Not objRecordSet.EOF 15 | strComputer = rtrim(objRecordSet("ComputerName")) 16 | 17 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 18 | Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_BIOS",,48) 19 | For Each objItem in colItems 20 | objRecordset1.AddNew 21 | objRecordset1("ComputerName") = rtrim(objRecordSet("ComputerName")) 22 | objRecordset1("BiosVersion") = RTrim(objItem.Manufacturer) & " " & objItem.Caption 23 | objRecordset1("SMBiosVersion") = objItem.SMBIOSMajorVersion & "." & objItem.SMBIOSMinorVersion 24 | Next 25 | objRecordset1.Update 26 | objRecordSet.MoveNext 27 | Loop 28 | objRecordset.Close 29 | objRecordset1.Close 30 | objConnection.Close -------------------------------------------------------------------------------- /vbs/playground/inventory1.vbs: -------------------------------------------------------------------------------- 1 | Const adOpenStatic = 3 2 | Const adLockOptimistic = 3 3 | Const adUseClient = 3 4 | Set objConnection = CreateObject("ADODB.Connection") 5 | Set objRecordset1 = CreateObject("ADODB.Recordset") 6 | objConnection.Open "DSN=NetworkInventory;" 7 | objRecordset1.CursorLocation = adUseClient 8 | objRecordset1.Open "SELECT * FROM Computers" , objConnection, _ 9 | adOpenStatic, adLockOptimistic 10 | 11 | Const ADS_SCOPE_SUBTREE = 2 12 | Set objConnection = CreateObject("ADODB.Connection") 13 | Set objCommand = CreateObject("ADODB.Command") 14 | objConnection.Provider = "ADsDSOObject" 15 | objConnection.Open "Active Directory Provider" 16 | Set objCommand.ActiveConnection = objConnection 17 | objCommand.CommandText = _ 18 | "SELECT Name, Location FROM 'LDAP://DC=company,DC=com' " _ 19 | & "WHERE objectClass='computer'" 20 | objCommand.Properties("Page Size") = 1000 21 | objCommand.Properties("Timeout") = 30 22 | objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 23 | objCommand.Properties("Cache Results") = False 24 | Set objRecordSet = objCommand.Execute 25 | objRecordSet.MoveFirst 26 | Do Until objRecordSet.EOF 27 | objRecordset1.AddNew 28 | objRecordset1("ComputerName") = objRecordSet.Fields("Name").Value 29 | objRecordSet.MoveNext 30 | objRecordset1.Update 31 | Loop 32 | objRecordset1.Close 33 | objConnection.Close -------------------------------------------------------------------------------- /vbs/playground/procedures/GetEvents.vbs: -------------------------------------------------------------------------------- 1 | Sub GetEvents(strComputer, strLogFile, intDays) 2 | ' 3 | ' This procedure returns events from the specified log 4 | ' from the provided computer. 5 | ' 6 | ' http://msdn.microsoft.com/en-us/library/aa394226(VS.85).aspx 7 | ' 8 | Dim dtmStartDate 9 | Dim dtmEndDate 10 | Dim objWMIService 11 | Dim colLoggedEvents 12 | Dim objEvent 13 | 14 | Set dtmStartDate = CreateObject("WbemScripting.SWbemDateTime") 15 | Set dtmEndDate = CreateObject("WbemScripting.SWbemDateTime") 16 | 17 | intDays = (intDays - intDays) - intDays 18 | dtmStartDate.SetVarDate now(), True 19 | dtmEndDate.SetVarDate DateAdd("d", intDays, now()), True 20 | 21 | Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 22 | Set colLoggedEvents = objWMIService.ExecQuery("Select * from Win32_NTLogEvent Where TimeWritten >= '" _ 23 | & dtmEndDate.Value & "' and TimeWritten < '" & dtmStartDate.Value _ 24 | & "' And Logfile = '" & strLogFile & "'") 25 | 26 | For Each objEvent in colLoggedEvents 27 | Wscript.Echo "Logname: " & objEvent.LogFile 28 | Wscript.Echo "EventId: " & objEvent.EventCode 29 | Wscript.Echo "Level: " & objEvent.Type 30 | Wscript.Echo "User: " & objEvent.User 31 | Wscript.Echo "Logged: " & objEvent.TimeWritten 32 | Wscript.Echo "Message: " & vbCrLf & objEvent.Message 33 | Next 34 | End Sub -------------------------------------------------------------------------------- /vbs/playground/procedures/ListFolders.txt: -------------------------------------------------------------------------------- 1 | Sub ListFolders(strComputer, strPath) 2 | On Error Resume Next 3 | ' 4 | ' Retrieves a list of subfolders from a specified parent folder 5 | ' 6 | ' http://www.microsoft.com/technet/scriptcenter/scripts/storage/folders/stfovb18.mspx?mfr=true 7 | ' 8 | Dim objWMIService 9 | Dim colSubfolders 10 | Dim objFolder 11 | Dim intIndex 12 | Dim objFSO 13 | 14 | Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 15 | Set colSubfolders = objWMIService.ExecQuery("Associators of {Win32_Directory.Name='" & strPath & "'} Where AssocClass = Win32_Subdirectory ResultRole = PartComponent") 16 | 17 | Set objFSO = CreateObject("Scripting.FileSystemObject") 18 | 19 | If objFSO.FolderExists(strPath) Then 20 | For Each objFolder in colSubfolders 21 | intIndex = intIndex + 1 22 | Next 23 | 24 | ReDim arrFolders(intIndex) 25 | intIndex = 0 26 | 27 | For Each objFolder in colSubfolders 28 | Select Case LCase(objFolder.Name) 29 | Case LCase(strPath & "\all users") 30 | Case LCase(strPath & "\default user") 31 | Case LCase(strPath & "\localservice") 32 | Case LCase(strPath & "\networkservice") 33 | Case Else 34 | arrFolders(intIndex) = objFolder.Name 35 | intIndex = intIndex + 1 36 | End Select 37 | Next 38 | Else 39 | Call LogData(1, "Folder not found: " & strPath) 40 | End If 41 | End Sub -------------------------------------------------------------------------------- /vbs/playground/ListObjectAttribs.vbs: -------------------------------------------------------------------------------- 1 | ' 2 | ' ListObjectAttribs 3 | ' 4 | ' This script lists all attributes for a given object 5 | ' within your AD. 6 | ' 7 | ' USAGE: 8 | ' 9 | ' The best way to run this is to redirect the output 10 | ' to a file. 11 | ' 12 | ' cscript //nologo ListObjectAttribs.vbs > ObjectAttribs.txt 13 | ' 14 | Dim strObject 15 | 16 | strObject = "computer" 17 | 18 | Set objGroupClass = GetObject("LDAP://schema/" & strObject) 19 | Set objSchemaClass = GetObject(objGroupClass.Parent) 20 | 21 | i = 0 22 | 23 | WScript.Echo "Mandatory attributes:" 24 | For Each strAttribute in objGroupClass.MandatoryProperties 25 | i = i + 1 26 | WScript.Echo i & vbTab & strAttribute 27 | 28 | Set objAttribute = objSchemaClass.GetObject("Property", strAttribute) 29 | WScript.Echo " (Syntax: " & objAttribute.Syntax & ")" 30 | 31 | If objAttribute.MultiValued Then 32 | WScript.Echo " Multivalued" 33 | Else 34 | WScript.Echo " Single-valued" 35 | End If 36 | Next 37 | 38 | WScript.Echo VbCrLf & "Optional attributes:" 39 | For Each strAttribute in objGroupClass.OptionalProperties 40 | i = i + 1 41 | Wscript.Echo i & vbTab & strAttribute 42 | Set objAttribute = objSchemaClass.GetObject("Property", strAttribute) 43 | 44 | Wscript.Echo " [Syntax: " & objAttribute.Syntax & "]" 45 | 46 | If objAttribute.MultiValued Then 47 | WScript.Echo " Multivalued" 48 | Else 49 | WScript.Echo " Single-valued" 50 | End If 51 | Next -------------------------------------------------------------------------------- /vbs/production/adutils/ListObjectAttribs.vbs: -------------------------------------------------------------------------------- 1 | ' 2 | ' ListObjectAttribs 3 | ' 4 | ' This script lists all attributes for a given object 5 | ' within your AD. 6 | ' 7 | ' USAGE: 8 | ' 9 | ' The best way to run this is to redirect the output 10 | ' to a file. 11 | ' 12 | ' cscript //nologo ListObjectAttribs.vbs > ObjectAttribs.txt 13 | ' 14 | Dim strObject 15 | 16 | strObject = "computer" 17 | 18 | Set objGroupClass = GetObject("LDAP://schema/" & strObject) 19 | Set objSchemaClass = GetObject(objGroupClass.Parent) 20 | 21 | i = 0 22 | 23 | WScript.Echo "Mandatory attributes:" 24 | For Each strAttribute in objGroupClass.MandatoryProperties 25 | i = i + 1 26 | WScript.Echo i & vbTab & strAttribute 27 | 28 | Set objAttribute = objSchemaClass.GetObject("Property", strAttribute) 29 | WScript.Echo " (Syntax: " & objAttribute.Syntax & ")" 30 | 31 | If objAttribute.MultiValued Then 32 | WScript.Echo " Multivalued" 33 | Else 34 | WScript.Echo " Single-valued" 35 | End If 36 | Next 37 | 38 | WScript.Echo VbCrLf & "Optional attributes:" 39 | For Each strAttribute in objGroupClass.OptionalProperties 40 | i = i + 1 41 | Wscript.Echo i & vbTab & strAttribute 42 | Set objAttribute = objSchemaClass.GetObject("Property", strAttribute) 43 | 44 | Wscript.Echo " [Syntax: " & objAttribute.Syntax & "]" 45 | 46 | If objAttribute.MultiValued Then 47 | WScript.Echo " Multivalued" 48 | Else 49 | WScript.Echo " Single-valued" 50 | End If 51 | Next -------------------------------------------------------------------------------- /vbs/production/utils/StartCommand.txt: -------------------------------------------------------------------------------- 1 | ' 2 | ' WindowStyle Variable 3 | ' http://msdn.microsoft.com/en-us/library/d5fk67ky(v=vs.85).aspx 4 | ' 5 | ' Defines the appearance of the program's window. 6 | ' 0 - Hides the window and activates another window. 7 | ' 1 - Activates and displays a window. 8 | ' 2 - Activates the window and displays it as a minimized window. 9 | ' 3 - Activates the window and displays it as a maximized window. 10 | ' 4 - Displays a window in its most recent size and position. The active window remains active. 11 | ' 5 - Activates the window and displays it in its current size and position. 12 | ' 6 - Minimizes the specified window and activates the next top-level window in the Z order. 13 | ' 7 - Displays the window as a minimized window. 14 | ' 8 - Displays the window in its current state. 15 | ' 9 - Activates and displays the window. 16 | ' 10 - Sets the show-state based on the state of the program that started the application. 17 | ' 18 | Function RunCommand(strCommand, intWindowStyle, blnReturnCode) 19 | ' 20 | ' This function uses the Run method of the Shell Object 21 | ' to launch a process on the computer. 22 | ' 23 | ' strCommand: Full path + command line of program to run 24 | ' intWindowStyle: An integer representing how to display the command window 25 | ' blnReturnCode: True/False if you want to return the exit code 26 | Dim objShell 27 | 28 | Set objShell = CreateObject("Wscript.Shell") 29 | RunCommand = objShell.Run(strCommand,intWindowStyle,blnReturnCode) 30 | End Function -------------------------------------------------------------------------------- /powershell/playground/mstsc.ps1: -------------------------------------------------------------------------------- 1 | param 2 | ( 3 | [string]$AccountName, 4 | [string]$Source = ".\" 5 | ) 6 | if ((New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) 7 | { 8 | $System32 = "C:\Windows\System32" 9 | $SysWow64 = "C:\Windows\SysWOW64" 10 | $mstsc = "mstsc.exe" 11 | $mstscax = "mstscax.dll" 12 | $Owner = New-Object System.Security.Principal.NTAccount($AccountName) 13 | $ACL.SetOwner($Owner) 14 | $Rule = New-Object System.Security.AccessControl.FileSystemAccessRule($Owner,"FullControl","Allow") 15 | $ACL.SetAccessRule($Rule) 16 | 17 | Set-Acl -Path "$($System32)\$($mstsc)" -AclObject $ACL 18 | Set-Acl -Path "$($System32)\$($mstscax)" -AclObject $ACL 19 | Set-Acl -Path "$($SysWow64)\$($mstsc)" -AclObject $ACL 20 | Set-Acl -Path "$($SysWow64)\$($mstscax)" -AclObject $ACL 21 | 22 | Rename-Item "$($System32)\$($mstsc)" "$($System32)\$($mstsc).$((Get-Date).ToFileTime().ToString())" 23 | Rename-Item "$($System32)\$($mstscax)" "$($System32)\$($mstscax).$((Get-Date).ToFileTime().ToString())" 24 | Rename-Item "$($SysWow64)\$($mstsc)" "$($SysWow64)\$($mstsc).$((Get-Date).ToFileTime().ToString())" 25 | Rename-Item "$($SysWow64)\$($mstscax)" "$($SysWow64)\$($mstscax).$((Get-Date).ToFileTime().ToString())" 26 | 27 | Copy-Item "$($Source)\System32\*" $System32 28 | Copy-Item "$($Source)\SysWOW64\*" $SysWow64 29 | } 30 | else 31 | { 32 | Write-Error "Launch Powershell as Administrator"; 33 | } -------------------------------------------------------------------------------- /vbs/playground/procedures/VariableWork.txt: -------------------------------------------------------------------------------- 1 | Sub VariableWork(strComputer, strUserName, strVarName, strVarValue, strAction) 2 | On Error Resume Next 3 | ' 4 | ' Based on strAction this subroutine will either update the variable or create it 5 | ' 6 | Dim objWMIService 7 | Dim colItems 8 | Dim objItem 9 | Dim objvariable 10 | Dim intErrCounter 11 | Dim dtmNewHour 12 | Dim dtmNewMinute 13 | Dim dtmNewSecond 14 | Dim dtmWaitTime 15 | 16 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") 17 | 18 | Select Case strAction 19 | Case "UPDATE" 20 | Set colItems = objWMIService.ExecQuery("Select * from Win32_Environment Where Name = '" & strVarName & "'") 21 | 22 | For Each objItem in colItems 23 | objItem.VariableValue = strVarValue 24 | objItem.Put_ 25 | Next 26 | Call LogData(0, "Updated: " & strVarName & vbCrLf & "Added: " & strVarValue) 27 | Case "CREATE" 28 | Set objVariable = objWMIService.Get("Win32_Environment").SpawnInstance_ 29 | 30 | objVariable.Name = strVarName 31 | objVariable.UserName = strUserName 32 | objVariable.VariableValue = strVarValue 33 | objVariable.Put_ 34 | If Err <> 0 Then 35 | Call Logdata(1, Err.Number & vbCrLf & Err.Description & vbCrLf & "CREATE FAILED: " & strVarName & "=" & strVarValue) 36 | Else 37 | Call LogData(0, "Created: " & strVarName & vbCrLf & "Added: " & strVarValue) 38 | End If 39 | Case Else 40 | Call LogData(1, "Something horribly wrong has happened.") 41 | End Select 42 | End Sub -------------------------------------------------------------------------------- /vbs/playground/procedures/DisplayEvents.txt: -------------------------------------------------------------------------------- 1 | Sub DisplayEvents(strComputerName, strDomain, strLogFile, strEventType, strEventCode) 2 | ' 3 | ' Display events from specified log 4 | ' 5 | ' strDomain = "HOME" 6 | ' strLogFile = "Security" 7 | ' strEventType = 4 8 | ' strEventCode = 528 9 | ' 10 | Dim strEventMessage 11 | Dim objWMIService 12 | Dim colLoggedEvents 13 | Dim arrFirst 14 | Dim finalArr 15 | Dim dtmDate 16 | Dim objEvent 17 | Dim strDomain 18 | Dim strUser 19 | Dim strLogFile 20 | Dim strEventType 21 | Dim strEventeCode 22 | 23 | Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate,(Security)}!\\" & strComputerName & ".soecs.ku.edu\root\cimv2") 24 | Set colLoggedEvents = objWMIService.ExecQuery("Select * FROM Win32_NTLogEvent WHERE Logfile = '" & strLogFile & "' AND EventType = " & strEventType & " AND EventCode = " & strEventCode & ") 25 | 26 | For Each objEvent In colLoggedEvents 27 | strEventMessage = Trim(objEvent.Message) 28 | arrFirst = split(strEventMessage, vbCrLf) 29 | strEventMessage = join(arrFirst, ":") 30 | arrFinal = split(strEventMessage, ":") 31 | dtmDate = Left(objEvent.TimeWritten,8) 32 | 33 | If UCase(replace(Trim(arrFinal(7)),vbTab,"")) = strDomain and Replace(Trim(arrFinal(13)),vbTab,"") = 2 And dtmDate > 20090421 Then 34 | strUser = replace(Trim(arrFinal(4)),vbTab,"") 35 | 'Wscript.Echo "Domain:" & replace(Trim(arrFinal(7)),vbTab,"") 36 | Wscript.Echo strComputerName & ", " & strUser & ", " & dtmDate 37 | End If 38 | Next 39 | 40 | End Sub -------------------------------------------------------------------------------- /wiki/DellWebsiteFunctions.wiki: -------------------------------------------------------------------------------- 1 | ==Get-!DellDownloadURL== 2 | {{{ 3 | Get-DellDownloadURL [[-ServiceTag] ] [[-DellCategory] ] 4 | 5 | }}} 6 | ==Get-!DellCurrentBIOSRev== 7 | {{{ 8 | Get-DellCurrentBIOSRev [[-ServiceTag] ] 9 | 10 | }}} 11 | ==Get-!DellWarranty== 12 | {{{ 13 | 14 | NAME 15 | Get-DellWarranty 16 | 17 | SYNOPSIS 18 | Quick script to invoke the Dell Jigsaw asset service. 19 | 20 | SYNTAX 21 | Get-DellWarranty [-ServiceTag] [] 22 | 23 | 24 | DESCRIPTION 25 | 26 | 27 | PARAMETERS 28 | -ServiceTag 29 | One or more valid Dell Service Tag codes, separated by commas 30 | 31 | Required? true 32 | Position? 1 33 | Default value 34 | Accept pipeline input? false 35 | Accept wildcard characters? 36 | 37 | 38 | This cmdlet supports the common parameters: Verbose, Debug, 39 | ErrorAction, ErrorVariable, WarningAction, WarningVariable, 40 | OutBuffer and OutVariable. For more information, type, 41 | "get-help about_commonparameters". 42 | 43 | INPUTS 44 | None. You cannot pipe to this script 45 | 46 | 47 | OUTPUTS 48 | PS Objects containing warranty support entitlements for the provided service tag 49 | 50 | 51 | 52 | RELATED LINKS 53 | 54 | 55 | 56 | }}} 57 | ==Get-!DellBIOSReport== 58 | {{{ 59 | Get-DellBIOSReport [[-ComputerName] ] 60 | 61 | }}} 62 | -------------------------------------------------------------------------------- /vbs/playground/functions/GetHostData.txt: -------------------------------------------------------------------------------- 1 | Function GetHostData(strSubNet) 2 | ' 3 | ' The purpose of this function is to build the data 4 | ' that is passed to other Functions. It will return 5 | ' information via WMI from the localhost. 6 | ' Currently all that's needed is: 7 | ' Bios serialnumber 8 | ' IP address 9 | ' MAC address 10 | ' hostname 11 | ' 12 | ' I do plan on gathering information about the OS 13 | ' and logged on user. 14 | ' 15 | ' This code has been reworked from the previous 16 | ' release, source:trunk/client/winmon-client.vbs 17 | ' 18 | ' In this release I have moved several things out 19 | ' to separate functions. 20 | ' 21 | ' Declare variables that are pulled from WMI 22 | ' 23 | Dim strSerialNumber 24 | Dim strMACAddress 25 | Dim strIPAddress 26 | Dim strHostName 27 | ' 28 | ' Declare variables that get built 29 | ' 30 | Dim strDate 31 | Dim strFieldValues 32 | ' 33 | ' Assign values to variables by calling Functions 34 | ' 35 | strSerialNumber = GetSerial(".") 36 | strMACAddress = GetMac(".", strSubNet) 37 | strIPAddress = GetIP(".", strMACAddress) 38 | strHostName = GetHost(".") 39 | ' 40 | ' Build the remaining required variables 41 | ' 42 | strDate = "" 43 | strDate = Year(Date) & "-" & Month(Date) & "-" & Day(Date) & " " & Hour(Now) & ":" & Minute(Now) & ":" & Second(Now) 44 | strFieldValues = "" 45 | strFieldValues = "'" & strSerialNumber & "','" & strHostName & "','" & strIPAddress & "','" & strMACAddress & "','" & strDate & "'" 46 | ' 47 | ' Assign the string to GetHostData 48 | ' 49 | GetHostData = strFieldValues 50 | End Function -------------------------------------------------------------------------------- /vbs/playground/procedures/CreateADObject.txt: -------------------------------------------------------------------------------- 1 | Sub CreateADObject(strObjectValue, strLDAPURL, strObject) 2 | ' 3 | ' This procedure will create one of four objects in AD 4 | ' Computer Objects 5 | ' User Objects 6 | ' Group Objects 7 | ' OU Objects 8 | ' 9 | ' strOBjectValue is the CanonicalName of the object 10 | ' to create. It is defined as either CN=THINGTOMAKE 11 | ' or OU=THINGTOMAKE depending on the thing. 12 | ' 13 | ' strLDAPURL is the LDAP URL where you want the thing 14 | ' to live. LDAP://CN=Computers,DC=company,DC=com 15 | ' 16 | ' strObject is the actual objet to create and needs 17 | ' to be defined as follows. 18 | ' organizationalUnit for an OU 19 | ' computer for a computer 20 | ' user for a user 21 | ' group for a group 22 | ' 23 | Dim objContainer 24 | Dim objADO 25 | 26 | Set objContainer = GetObject(strLDAPURL) 27 | Set objADO = objContainer.Create(strObject, strObjectValue) 28 | strObjectValue = Right(strObjectValue, Len(strObjectValue)-3) 29 | 30 | Select Case LCase(strObject) 31 | Case "computer" 32 | Const ADS_UF_PASSWD_NOTREQD = &h0020 33 | Const ADS_UF_WORKSTATION_TRUST_ACCOUNT = &h1000 34 | 35 | objADO.Put "sAMAccountName", strObjectValue & "$" 36 | objADO.Put "userAccountControl", ADS_UF_PASSWD_NOTREQD Or ADS_UF_WORKSTATION_TRUST_ACCOUNT 37 | objADO.SetInfo 38 | Case "user" 39 | objADO.Put "sAMAccountName", strObjectValue 40 | objADO.SetInfo 41 | Case "group" 42 | objADO.Put "sAMAccountName", strObjectValue 43 | objADO.SetInfo 44 | Case "organizationalunit" 45 | objADO.SetInfo 46 | Case Else 47 | End Select 48 | End Sub -------------------------------------------------------------------------------- /vbs/playground/os.vbs: -------------------------------------------------------------------------------- 1 | Const adOpenStatic = 3 2 | Const adLockOptimistic = 3 3 | Const adUseClient = 3 4 | Set objConnection = CreateObject("ADODB.Connection") 5 | Set objRecordset = CreateObject("ADODB.Recordset") 6 | objConnection.Open "DSN=NetworkInventory;" 7 | objRecordset.CursorLocation = adUseClient 8 | objRecordset.Open "SELECT * FROM Computers where computername='SOECS-ST-PATTON'" , objConnection, adOpenStatic, adLockOptimistic 9 | objRecordSet.MoveFirst 10 | Do While Not objRecordSet.EOF 11 | strComputer = rtrim(objRecordSet("ComputerName")) 12 | 13 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 14 | Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem",,48) 15 | For Each objItem in colItems 16 | Wscript.Echo "OS Name: " & objItem.Caption 17 | Wscript.Echo "Version: " & objItem.Version & " Service Pack " & objItem.ServicePackMajorVersion 18 | Next 19 | 20 | Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem",,48) 21 | For Each objItem in colItems 22 | Wscript.Echo "System Name: " & objItem.Name 23 | Wscript.Echo "System Manufacturer: " & objItem.Manufacturer 24 | WScript.Echo "System Model: " & objItem.Model 25 | Next 26 | 27 | Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem",,48) 28 | For Each objItem in colItems 29 | Wscript.Echo "Windows Directory: " & objItem.WindowsDirectory 30 | Wscript.Echo "System Directory: " & objItem.SystemDirectory 31 | Wscript.Echo "Boot Device: " & objItem.BootDevice 32 | Next 33 | 34 | objRecordSet.MoveNext 35 | Loop 36 | objRecordset.Close 37 | objConnection.Close -------------------------------------------------------------------------------- /vbs/playground/procedures/SecLog.txt: -------------------------------------------------------------------------------- 1 | Sub SecLog(strComputerName) 2 | On Error Resume Next 3 | ' 4 | ' This procedure can be used to pull information from the security log 5 | ' 6 | 7 | Dim objWMIService 8 | Dim colLoggedEvents 9 | Dim strEventMessage 10 | Dim arrFirst 11 | Dim arrFinal 12 | Dim dtmDate 13 | Dim objEvent 14 | Dim strLogFile 15 | Dim strEventType 16 | Dim strEventeCode 17 | 18 | strLogFile = "Security" 19 | strEventType = 4 20 | strEventCode = 528 21 | 22 | Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate,(Security)}!\\" & strComputerName & ".soecs.ku.edu\root\cimv2") 23 | If Err <> 0 Then Call LogData(1, "Unable to connect to " & strComputerName) 24 | Set colLoggedEvents = objWMIService.ExecQuery("Select * FROM Win32_NTLogEvent WHERE Logfile = '" & strLogFile & "' AND EventType = " & strEventType & " AND EventCode = " & strEventCode & ") 25 | 26 | For Each objEvent In colLoggedEvents 27 | strEventMessage = Trim(objEvent.Message) 28 | arrFirst = split(strEventMessage, vbCrLf) 29 | strEventMessage = join(arrFirst, ":") 30 | arrFinal = split(strEventMessage, ":") 31 | dtmDate = Left(objEvent.TimeWritten,8) 32 | 33 | Wscript.Echo "Category: " & objEvent.Category 34 | Wscript.Echo "Computer Name: " & objEvent.ComputerName 35 | Wscript.Echo "Event Code: " & objEvent.EventCode 36 | Wscript.Echo "Message: " & objEvent.Message 37 | Wscript.Echo "Record Number: " & objEvent.RecordNumber 38 | Wscript.Echo "Source Name: " & objEvent.SourceName 39 | Wscript.Echo "Time Written: " & objEvent.TimeWritten 40 | Wscript.Echo "Event Type: " & objEvent.Type 41 | Wscript.Echo "User: " & objEvent.User 42 | 43 | Next 44 | 45 | End Sub -------------------------------------------------------------------------------- /vbs/production/wmiutils/DisableNICPowerManagement.vbs: -------------------------------------------------------------------------------- 1 | Sub DisableNICPowerManagement(strComputer, intDWordValue) 2 | ' This procedure allows you to enable or disable the PowerManagement 3 | ' features of a network card. 4 | ' 5 | ' To disable intDWordValue = 56 6 | ' To enable intDWordValue = 48 7 | ' 8 | ' This subroutine updates the registry to make the change so the 9 | ' target computer will need to reboot before the change kicks in. 10 | ' 11 | ' The GUID of Network Cards: http://technet.microsoft.com/en-us/library/cc780532(WS.10).aspx 12 | ' The value to set for PnPCapabilities: http://support.microsoft.com/kb/837058 13 | ' The WMI Class we want (Win32_NetworkAdapter): http://msdn.microsoft.com/en-us/library/aa394216(v=vs.85).aspx 14 | ' From that class what we need is the Index property, this number represents the specific 15 | ' network card we wish to manipulate. 16 | On Error Resume Next 17 | 18 | Const HKLM = &H80000002 19 | Dim objReg 20 | Dim objWMIService 21 | Dim colItems 22 | Dim objItem 23 | Dim strRegKey 24 | 25 | strRegKey = "SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\" 26 | 27 | Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv") 28 | Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 29 | Set colItems = objWMIService.ExecQuery ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True") 30 | 31 | For Each objItem in colItems 32 | If Len(objItem.Index) = 1 Then strDeviceID = "000" & objItem.Index 33 | If Len(objItem.Index) = 2 Then strDeviceID = "00" & objItem.Index 34 | If Len(objItem.Index) = 3 Then strDeviceID = "0" & objItem.Index 35 | objReg.SetDWORDValue HKLM, strRegKey & strDeviceID & "\","PnPCapabilities",intDWordValue 36 | Next 37 | End Sub -------------------------------------------------------------------------------- /vbs/playground/Memory.vbs: -------------------------------------------------------------------------------- 1 | Const adOpenStatic = 3 2 | Const adLockOptimistic = 3 3 | Const adUseClient = 3 4 | Set objConnection = CreateObject("ADODB.Connection") 5 | Set objRecordset = CreateObject("ADODB.Recordset") 6 | Set objRecordset1 = CreateObject("ADODB.Recordset") 7 | objConnection.Open "DSN=NetworkInventory;" 8 | objRecordset.CursorLocation = adUseClient 9 | objRecordset.Open "SELECT * FROM Computers where computername='SOECS-ST-PATTON'" , objConnection, adOpenStatic, adLockOptimistic 10 | 11 | objRecordset1.Open "SELECT * FROM OS" , objConnection, adOpenStatic, adLockOptimistic 12 | 13 | objRecordSet.MoveFirst 14 | Do While Not objRecordSet.EOF 15 | strComputer = rtrim(objRecordSet("ComputerName")) 16 | 17 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 18 | Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem",,48) 19 | objRecordset1.AddNew 20 | objRecordset1("ComputerName") = rtrim(objRecordSet("ComputerName")) 21 | For Each objItem in colItems 22 | objRecordset1("OSName") = objItem.Caption 23 | objRecordset1("OSVersion") = objItem.Version & " Service Pack " & objItem.ServicePackMajorVersion 24 | Next 25 | 26 | Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem",,48) 27 | For Each objItem in colItems 28 | objRecordset1("SystemManufacturer") = objItem.Manufacturer 29 | objRecordset1("SystemModel") = objItem.Model 30 | Next 31 | 32 | Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem",,48) 33 | For Each objItem in colItems 34 | objRecordset1("WindowsDirectory") = objItem.WindowsDirectory 35 | objRecordset1("SystemDirectory") = objItem.SystemDirectory 36 | objRecordset1("BootDevice") = objItem.BootDevice 37 | Next 38 | 39 | objRecordset1.Update 40 | objRecordSet.MoveNext 41 | Loop 42 | objRecordset.Close 43 | objRecordset1.Close 44 | objConnection.Close -------------------------------------------------------------------------------- /vbs/playground/functions/GetSoftware.txt: -------------------------------------------------------------------------------- 1 | Function GetSoftware(blnSMS) 2 | ' 3 | ' Based on blnSMS this function will make one of 4 | ' two WMI calls to return a list of software. 5 | ' 6 | ' WMI Variables 7 | ' 8 | Dim objWMIService 9 | Dim colItems 10 | Dim objItem 11 | ' 12 | ' Variables we will build later 13 | ' 14 | Dim strSoftware 15 | Dim strInstallDate 16 | Dim strVendor 17 | Dim strVersion 18 | Dim strSoftwareName 19 | Dim strIdentNum 20 | 21 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 22 | strSoftware = "" 23 | 24 | Select Case blnSMS 25 | Case vbYes 26 | Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32Reg_AddRemovePrograms",,48) 27 | 28 | For Each objItem in colItems 29 | strSoftwareName = objItem.DisplayName 30 | strIdentNum = objItem.ProdID 31 | strInstallDate = objItem.InstallDate 32 | strInstallDate = left(strInstallDate, 4) & "-" & mid(strInstallDate, 5, 2) & "-" & right(strInstallDate, 2) 33 | strVendor = objItem.Publisher 34 | strVersion = objItem.Version 35 | strSoftware = "'" & strSoftwareName & "','" & strIdentNum & "','" & strInstallDate & "','" & strVendor & "','" & strVersion &"'" 36 | Next 37 | Case vbNo 38 | Set colItems = objWMIService.ExecQuery("SELECT Name, IdentifyingNumber, InstallDate, Vendor, Version FROM Win32_Product",,48) 39 | 40 | For Each objItem in colItems 41 | strSoftwareName = objItem.Name 42 | strIdentNum = objItem.IdentifyingNumber 43 | strInstallDate = objItem.InstallDate 44 | strInstallDate = left(strInstallDate, 4) & "-" & mid(strInstallDate, 5, 2) & "-" & right(strInstallDate, 2) 45 | strVendor = objItem.Vendor 46 | strVersion = objItem.Version 47 | strSoftware = "'" & strSoftwareName & "','" & strIdentNum & "','" & strInstallDate & "','" & strVendor & "','" & strVersion & "'" 48 | Next 49 | Case Else 50 | End Select 51 | GetSoftware = strSoftware 52 | End Function -------------------------------------------------------------------------------- /powershell/playground/Setup-Workstation.ps1: -------------------------------------------------------------------------------- 1 | if ($Global:principal.IsInRole("Administrators")) { 2 | # Get my current profile 3 | Invoke-WebRequest -UseBasicParsing -Uri "https://raw.githubusercontent.com/jeffpatton1971/mod-posh/master/powershell/playground/Profile.ps1" -OutFile $PROFILE; 4 | # Get USB DVD Tool 5 | Invoke-WebRequest -UseBasicParsing -Uri "https://download.microsoft.com/download/C/4/8/C48F6E20-FE20-41C6-8C1C-408FE7B49A3A/Windows7-USB-DVD-Download-Tool-Installer-en-US.exe" -OutFile .\Windows7-USB-DVD-tool.exe; 6 | # Get Exchange Web Services 7 | Invoke-WebRequest -UseBasicParsing -Uri "http://download.microsoft.com/download/5/E/4/5E456B4C-78D4-4E6C-BC84-CA7FE87BB117/WebServicesSDK.msi" -OutFile .\WebServicesSDK.msi; 8 | # Get WebPI 9 | Invoke-WebRequest -UseBasicParsing -Uri "https://download.microsoft.com/download/8/4/9/849DBCF2-DFD9-49F5-9A19-9AEE5B29341A/WebPlatformInstaller_x64_en-US.msi" -OutFile .\WebPlatformInstaller_x64_en-US.msi; 10 | # Get GithubDesktop 11 | Invoke-WebRequest -UseBasicParsing -Uri "https://desktop.githubusercontent.com/releases/2.4.3-539849ed/GitHubDesktopSetup.exe" -OutFile .\GitHubDesktopSetup.exe; 12 | # Get VsCode 13 | Invoke-WebRequest -UseBasicParsing -Uri "https://az764295.vo.msecnd.net/stable/ff915844119ce9485abfe8aa9076ec76b5300ddd/VSCodeUserSetup-x64-1.44.2.exe" -OutFile .\VSCodeUserSetup-x64-1.44.2.exe; 14 | # Get Posh-Git 15 | Install-Module -Name posh-git -AllowClobber; 16 | Write-Host "You will need to install Visual Studio in order to compile CShell" 17 | # Get C-Shell 18 | git clone https://github.com/lukebuehler/CShell.git 19 | # ADO Artifacts Credential Provider 20 | Invoke-Expression "& { $(Invoke-RestMethod https://aka.ms/install-artifacts-credprovider.ps1) }" 21 | Invoke-Expression "& { $(Invoke-RestMethod https://aka.ms/install-artifacts-credprovider.ps1) } -AddNetfx" 22 | } else { 23 | Write-Host "Please launch PowerShell as an Administrator" -ForegroundColor Red; 24 | } -------------------------------------------------------------------------------- /wiki/GetSisStatusReport.wiki: -------------------------------------------------------------------------------- 1 | = !Get-SisStatusReport.ps1 = 2 | {{{ 3 | 4 | NAME 5 | C:\mod-posh\powershell\production\Get-SisStatusReport.ps1 6 | 7 | SYNOPSIS 8 | Get SIS Status 9 | 10 | SYNTAX 11 | C:\mod-posh\powershell\production\Get-SisStatusReport.ps1 [[-Disks] ] [] 13 | 14 | 15 | DESCRIPTION 16 | This script uses Get-SisReport to get the status of SiS'd disks on a storage server. 17 | 18 | 19 | PARAMETERS 20 | -Disks 21 | Requires a disk object, if left blank gets all disks where the Provider 22 | is filesystem. 23 | 24 | Required? false 25 | Position? 1 26 | Default value 27 | Accept pipeline input? false 28 | Accept wildcard characters? 29 | 30 | 31 | This cmdlet supports the common parameters: Verbose, Debug, 32 | ErrorAction, ErrorVariable, WarningAction, WarningVariable, 33 | OutBuffer and OutVariable. For more information, type, 34 | "get-help about_commonparameters". 35 | 36 | INPUTS 37 | 38 | OUTPUTS 39 | 40 | NOTES 41 | 42 | 43 | ScriptName: Get-SisStatusReport.ps1 44 | Created By: Jeff Patton 45 | Date Coded: July 8, 2011 46 | ScriptName is used to register events for this script 47 | LogName is used to determine which classic log to write to 48 | 49 | This script will only work on a server with the Enterprise SKU 50 | and where SIS is enabled on a given volume. 51 | 52 | -------------------------- EXAMPLE 1 -------------------------- 53 | 54 | C:\PS>.\Get-SisStatusReport.ps1 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | RELATED LINKS 65 | https://code.google.com/p/mod-posh/wiki/Get-SisStatusReport 66 | 67 | 68 | 69 | }}} 70 | -------------------------------------------------------------------------------- /vbs/playground/sample-vbs.txt: -------------------------------------------------------------------------------- 1 | ' 2 | ' Sample Script 3 | ' 4 | ' This script contains the basic logging information that I use everywhere 5 | ' 6 | Call LogData(4, ScriptDetails(".") & vbCrLf & "Started: " & Now()) 7 | 8 | Call LogData(4, ScriptDetails(".") & vbCrLf & "Finished: " & Now()) 9 | 10 | 11 | Sub LogData(intCode, strMessage) 12 | ' Write data to application log 13 | ' 14 | ' http://www.microsoft.com/technet/scriptcenter/guide/default.mspx?mfr=true 15 | ' 16 | ' Event Codes 17 | ' 0 = Success 18 | ' 1 = Error 19 | ' 2 = Warning 20 | ' 4 = Information 21 | Dim objShell 22 | 23 | Set objShell = Wscript.CreateObject("Wscript.Shell") 24 | 25 | objShell.LogEvent intCode, strMessage 26 | 27 | End Sub 28 | 29 | Function ScriptDetails(strComputer) 30 | ' 31 | ' Return information about who, what, where 32 | ' 33 | On Error Resume Next 34 | Dim strScriptName 35 | Dim strScriptPath 36 | Dim strUserName 37 | Dim objWMIService 38 | Dim colProcesslist 39 | Dim objProcess 40 | Dim colProperties 41 | Dim strNameOfUser 42 | Dim struserDomain 43 | 44 | strScriptName = Wscript.ScriptName 45 | strScriptPath = Wscript.ScriptFullName 46 | 47 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") 48 | Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process Where Name = 'cscript.exe' or Name = 'wscript.exe'") 49 | 50 | For Each objProcess in colProcessList 51 | If InStr(objProcess.CommandLine, strScriptName) Then 52 | colProperties = objProcess.GetOwner(strNameOfUser,strUserDomain) 53 | If Err <> 0 Then 54 | Call LogData(1, "Error Number: " & vbTab & Err.Number & vbCrLf & "Error Description: " & vbTab & Err.Description) 55 | Err.Clear 56 | Exit For 57 | End If 58 | strUserName = strUserDomain & "\" & strNameOfUser 59 | End If 60 | Next 61 | 62 | ScriptDetails = "Script Name: " & strScriptName & vbCrLf & "Script Path: " & strScriptPath & vbCrLf & "Script User: " & strUserName 63 | End Function -------------------------------------------------------------------------------- /vbs/playground/sample.txt: -------------------------------------------------------------------------------- 1 | ' 2 | ' Sample Script 3 | ' 4 | ' This script contains the basic logging information that I use everywhere 5 | ' 6 | Call LogData(4, ScriptDetails(".") & vbCrLf & "Started: " & Now()) 7 | 8 | Call LogData(4, ScriptDetails(".") & vbCrLf & "Finished: " & Now()) 9 | 10 | 11 | Sub LogData(intCode, strMessage) 12 | ' Write data to application log 13 | ' 14 | ' http://www.microsoft.com/technet/scriptcenter/guide/default.mspx?mfr=true 15 | ' 16 | ' Event Codes 17 | ' 0 = Success 18 | ' 1 = Error 19 | ' 2 = Warning 20 | ' 4 = Information 21 | Dim objShell 22 | 23 | Set objShell = Wscript.CreateObject("Wscript.Shell") 24 | 25 | objShell.LogEvent intCode, strMessage 26 | 27 | End Sub 28 | 29 | Function ScriptDetails(strComputer) 30 | ' 31 | ' Return information about who, what, where 32 | ' 33 | On Error Resume Next 34 | Dim strScriptName 35 | Dim strScriptPath 36 | Dim strUserName 37 | Dim objWMIService 38 | Dim colProcesslist 39 | Dim objProcess 40 | Dim colProperties 41 | Dim strNameOfUser 42 | Dim struserDomain 43 | 44 | strScriptName = Wscript.ScriptName 45 | strScriptPath = Wscript.ScriptFullName 46 | 47 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") 48 | Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process Where Name = 'cscript.exe' or Name = 'wscript.exe'") 49 | 50 | For Each objProcess in colProcessList 51 | If InStr(objProcess.CommandLine, strScriptName) Then 52 | colProperties = objProcess.GetOwner(strNameOfUser,strUserDomain) 53 | If Err <> 0 Then 54 | Call LogData(1, "Error Number: " & vbTab & Err.Number & vbCrLf & "Error Description: " & vbTab & Err.Description) 55 | Err.Clear 56 | Exit For 57 | End If 58 | strUserName = strUserDomain & "\" & strNameOfUser 59 | End If 60 | Next 61 | 62 | ScriptDetails = "Script Name: " & strScriptName & vbCrLf & "Script Path: " & strScriptPath & vbCrLf & "Script User: " & strUserName 63 | End Function -------------------------------------------------------------------------------- /powershell/production/includes/CarsonADLibraries.psm1: -------------------------------------------------------------------------------- 1 | function Convert-ObjectSID { 2 | <# 3 | .SYNOPSIS 4 | Convert a string SID to an object 5 | .DESCRIPTION 6 | This function returns an object 7 | .PARAMETER ObjectSID 8 | The SID of the account 9 | .EXAMPLE 10 | Convert-ObjectSID -ObjectSID S-1-5-21-57989841-1078081533-682003330-187082 |Format-Table -AutoSize 11 | 12 | BinaryLength AccountDomainSid Value 13 | ------------ ---------------- ----- 14 | 28 S-1-5-21-57989841-1078081533-682003330 S-1-5-21-57989841-1078081533-682003330-187082 15 | 16 | Description 17 | ----------- 18 | Showing the basic syntax and output of the function. 19 | .NOTES 20 | This function was originall written by Carson Gee (http://carsongee.com) 21 | .LINK 22 | https://code.google.com/p/mod-posh/wiki/CarsonADLibraries#Convert-ObjectSID 23 | #> 24 | [CmdletBinding()] 25 | Param 26 | ( 27 | $ObjectSID 28 | ) 29 | return New-Object System.Security.Principal.SecurityIdentifier($ObjectSID) 30 | } 31 | function Convert-SIDToUser { 32 | <# 33 | .SYNOPSIS 34 | Convert SID to a user object 35 | .DESCRIPTION 36 | This function takes a SID object and converts it to a user object 37 | .PARAMETER ObjectSID 38 | The SID object of the user account, this cannot be the string. Use 39 | Convert-ObjectSID to get the objectified SID from a string. 40 | .EXAMPLE 41 | Convert-SIDToUser -ObjectSID (Convert-ObjectSID -ObjectSID S-1-5-21-57989841-1078081533-682003330-18 42 | 7082) 43 | 44 | Value 45 | ----- 46 | HOME\s071b751 47 | 48 | Description 49 | ----------- 50 | Shows the basic usage of the command. 51 | .NOTES 52 | This function was originall written by Carson Gee (http://carsongee.com) 53 | .LINK 54 | https://code.google.com/p/mod-posh/wiki/CarsonADLibraries#Convert-SIDToUser 55 | #> 56 | [CmdletBinding()] 57 | Param 58 | ( 59 | $ObjectSID 60 | ) 61 | return $ObjectSID.Translate([System.Security.Principal.NTAccount]) 62 | } 63 | 64 | Export-ModuleMember * -------------------------------------------------------------------------------- /powershell/production/includes/PerformanceTesting.psm1: -------------------------------------------------------------------------------- 1 | Function Get-AverageRunTime { 2 | <# 3 | .SYNOPSIS 4 | Return the average time in milliseconds it takes a command to run. 5 | .DESCRIPTION 6 | This function returns the average time in milliseconds for a command to run over several iterations. 7 | Simply pass in the number of iterations, and the script block you wish to test. 8 | .PARAMETER Counter 9 | A number representing how many times to time the block. 10 | .PARAMETER ScriptBlock 11 | A valid cmdlet or block of code for example: 12 | 13 | Start-Sleep 5 14 | Get-Process 15 | Get-WmiObject win32_bios -ComputerName server01 16 | .EXAMPLE 17 | Get-AverageRunTime 18 | Average time of 5 runs of 5 seconds is 5005.9882 milliseconds. 19 | 20 | Description 21 | ----------- 22 | An example showing the function running with no parameters. 23 | .EXAMPLE 24 | Get-AverageRunTime -Counter 3 25 | Average time of 3 runs of 5 seconds is 5006.80143333333 milliseconds. 26 | 27 | Description 28 | ----------- 29 | An example showing the function with a different counter value. 30 | .EXAMPLE 31 | Get-AverageRunTime -Counter 5 -ScriptBlock "Start-Sleep 3" 32 | Average time of 5 runs of (Start-Sleep 3) is 3008.26246 milliseconds 33 | 34 | Description 35 | ----------- 36 | This example shows the use of both the ScriptBlock and Counter parameters. 37 | .NOTES 38 | .LINK 39 | https://code.google.com/p/mod-posh/wiki/PerformanceTesting#Get-AverageRunTime 40 | #> 41 | [CmdletBinding()] 42 | Param 43 | ( 44 | $Counter = 5, 45 | $ScriptBlock = 'Start-Sleep 5' 46 | ) 47 | Begin { 48 | } 49 | Process { 50 | $Counter = 0..($Counter - 1) 51 | $TotalMilliseconds = ( 52 | (Measure-Command { ForEach ($Count In $Counter) 53 | { Measure-Command { Invoke-Expression $ScriptBlock } } }).TotalMilliseconds / [int]$Counter.Count) 54 | } 55 | End { 56 | Return "Average time of " + $Counter.Count + " runs of (" + $ScriptBlock + ") is " ` 57 | + $TotalMilliseconds + " milliseconds" 58 | } 59 | } 60 | 61 | Export-ModuleMember * -------------------------------------------------------------------------------- /wiki/GetLocalProfiles.wiki: -------------------------------------------------------------------------------- 1 | = !Get-LocalProfiles.ps1 = 2 | {{{ 3 | 4 | NAME 5 | C:\mod-posh\powershell\production\Get-LocalProfiles.ps1 6 | 7 | SYNOPSIS 8 | Get a count of local profiles 9 | 10 | SYNTAX 11 | C:\mod-posh\powershell\production\Get-LocalProfiles.ps1 [[-ADSPath] ] [] 13 | 14 | 15 | DESCRIPTION 16 | This scrpit displays a count of the users who have logged in to each 17 | computer. 18 | 19 | 20 | PARAMETERS 21 | -ADSPath 22 | The LDAP URL to where the computers you are interested in are located 23 | in the directory. 24 | 25 | Required? false 26 | Position? 1 27 | Default value 28 | Accept pipeline input? false 29 | Accept wildcard characters? 30 | 31 | 32 | This cmdlet supports the common parameters: Verbose, Debug, 33 | ErrorAction, ErrorVariable, WarningAction, WarningVariable, 34 | OutBuffer and OutVariable. For more information, type, 35 | "get-help about_commonparameters". 36 | 37 | INPUTS 38 | 39 | OUTPUTS 40 | 41 | NOTES 42 | 43 | 44 | ScriptName : Get-LocalProfiles 45 | Created By : jspatton 46 | Date Coded : 10/06/2011 08:48:37 47 | ScriptName is used to register events for this script 48 | LogName is used to determine which classic log to write to 49 | 50 | ErrorCodes 51 | 100 = Success 52 | 101 = Error 53 | 102 = Warning 54 | 104 = Information 55 | 56 | -------------------------- EXAMPLE 1 -------------------------- 57 | 58 | C:\PS>.\Get-LocalProfiles.ps1 -ADSPath 'OU=Workstations,OU=ADmin,DC=company,DC=com' 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | RELATED LINKS 69 | https://code.google.com/p/mod-posh/wiki/Get-LocalProfiles 70 | 71 | 72 | 73 | }}} 74 | -------------------------------------------------------------------------------- /vbs/playground/RegWrite.vbs: -------------------------------------------------------------------------------- 1 | Call QueryAD("SELECT DistinguishedName ,Name FROM 'LDAP://OU=Labs,DC=company,DC=com' WHERE objectClass = 'computer'") 2 | 3 | Sub QueryAD(strQuery) 4 | On Error Resume Next 5 | ' 6 | ' This procedure will loop through a recordset of objects 7 | ' returned from a query. 8 | ' 9 | Const ADS_SCOPE_SUBTREE = 2 10 | Dim objConnection 11 | Dim objCommand 12 | Dim objRecordset 13 | 14 | Set objConnection = CreateObject("ADODB.Connection") 15 | Set objCommand = CreateObject("ADODB.Command") 16 | objConnection.Provider = "ADsDSOObject" 17 | objConnection.Open "Active Directory Provider" 18 | 19 | Set objCOmmand.ActiveConnection = objConnection 20 | objCommand.CommandText = strQuery 21 | objCommand.Properties("Page Size") = 1000 22 | objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 23 | Set objRecordSet = objCommand.Execute 24 | If Err <> 0 Then Call LogData(1, "Unable to connect using the provided query: " & vbCrLf & strQuery) 25 | 26 | objRecordSet.MoveFirst 27 | 28 | Do Until objRecordSet.EOF 29 | Call AddVar("UGS_LICENSE_BUNDLE", "ACD", "REG_SZ") 30 | objRecordSet.MoveNext 31 | Loop 32 | End Sub 33 | 34 | Sub AddVar(strVariable, strVariableValue, strVariableType) 35 | ' 36 | ' This procedure adds environment variables reliably 37 | ' 38 | ' http://msdn.microsoft.com/en-us/library/yfdfhz1b(VS.85).aspx 39 | ' 40 | Dim WshShell 41 | Set WshShell = WScript.CreateObject("WScript.Shell") 42 | 43 | WshShell.RegWrite"HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\" & strVariable, strVariableValue, strVariableType 44 | If Err <> 0 Then Call LogData(1, "Unable to add " & strvariable & " = " & strVariableValue) 45 | 46 | End Sub 47 | 48 | Sub LogData(intCode, strMessage) 49 | ' Write data to application log 50 | ' 51 | ' http://www.microsoft.com/technet/scriptcenter/guide/default.mspx?mfr=true 52 | ' 53 | ' Event Codes 54 | ' 0 = Success 55 | ' 1 = Error 56 | ' 2 = Warning 57 | ' 4 = Information 58 | Dim objShell 59 | 60 | Set objShell = Wscript.CreateObject("Wscript.Shell") 61 | 62 | objShell.LogEvent intCode, strMessage 63 | 64 | End Sub 65 | 66 | -------------------------------------------------------------------------------- /vbs/playground/Processor.vbs: -------------------------------------------------------------------------------- 1 | Const adOpenStatic = 3 2 | Const adLockOptimistic = 3 3 | Const adUseClient = 3 4 | Set objConnection = CreateObject("ADODB.Connection") 5 | Set objRecordset = CreateObject("ADODB.Recordset") 6 | Set objRecordset1 = CreateObject("ADODB.Recordset") 7 | objConnection.Open "DSN=NetworkInventory;" 8 | objRecordset.CursorLocation = adUseClient 9 | objRecordset.Open "SELECT * FROM Computers where computername='SOECS-ST-PATTON'" , objConnection, adOpenStatic, adLockOptimistic 10 | 11 | objRecordset1.Open "SELECT * FROM Memory" , objConnection, adOpenStatic, adLockOptimistic 12 | 13 | objRecordSet.MoveFirst 14 | Do While Not objRecordSet.EOF 15 | strComputer = rtrim(objRecordSet("ComputerName")) 16 | 17 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 18 | Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalMemoryConfiguration",,48) 19 | objRecordset1.AddNew 20 | objRecordset1("ComputerName") = rtrim(objRecordSet("ComputerName")) 21 | For Each objItem in colItems 22 | objRecordset1("TotalPhysicalMemory") = round(( objItem.TotalPhysicalMemory/1024)) & "MB" 23 | Next 24 | 25 | Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem",,48) 26 | For Each objItem in colItems 27 | objRecordset1("AvailablePhysicalMemory") = round(((objItem.FreePhysicalMemory/1024)/1024),2) & "GB" 28 | objRecordset1("TotalVirtualMemory") = round(((objItem.TotalVirtualMemorySize/1024)/1024),2) & "GB" 29 | objRecordset1("AvailableVirtualMemory") = round(((objItem.FreeVirtualMemory/1024)/1024),2) & "GB" 30 | Next 31 | 32 | Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalMemoryConfiguration",,48) 33 | For Each objItem in colItems 34 | objRecordset1("PageFileSpace") = round(((objItem.TotalPageFileSpace/1024)/1024),2) & "GB" 35 | Next 36 | 37 | Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PageFile",,48) 38 | For Each objItem in colItems 39 | objRecordset1("PageFile") = objItem.Caption 40 | Next 41 | objRecordset1.Update 42 | objRecordSet.MoveNext 43 | Loop 44 | objRecordset.Close 45 | objRecordset1.Close 46 | objConnection.Close -------------------------------------------------------------------------------- /powershell/playground/Profile.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | This is my custom prompt for PowerShell. 3 | 4 | It displays username@computername | current time | current date | working directory 5 | 6 | The last character will be either $ for users NOT in administrators group 7 | or # for users IN administrators group 8 | 9 | #> 10 | $Global:Admin="$" 11 | $Global:CurrentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent() 12 | $Global:principal = new-object System.Security.principal.windowsprincipal($Global:CurrentUser) 13 | if ($Host.Name -eq 'ConsoleHost') { 14 | # 15 | # Set default editor 16 | # 17 | $Global:POSHEditor = "$env:LOCALAPPDATA\Programs\Microsoft VS Code\bin\code.cmd" 18 | 19 | # 20 | # Start transcription 21 | # 22 | Start-Transcript 23 | } 24 | # 25 | # Import posh-git 26 | # 27 | Import-Module -Name posh-git; 28 | # 29 | # Move me into my code location 30 | # 31 | Set-Location "C:\projects\mod-posh\powershell\production" 32 | # 33 | # Dot source in my functions 34 | # 35 | Get-ChildItem .\includes\*.psm1 |ForEach-Object {Import-Module $_.FullName} 36 | # 37 | # Change prompt to # if i have admin rights 38 | # 39 | if ($Global:principal.IsInRole("Administrators")) 40 | { 41 | $Admin="#" 42 | } 43 | 44 | # 45 | # Setup my custom prompt 46 | # 47 | Function prompt { 48 | $Now = $(get-date).Tostring("HH:mm:ss | MM-dd-yyy") 49 | $FreeSpace = [math]::Round(((Get-PSDrive ((pwd).drive |Select-Object -ExpandProperty name) |Select-Object -ExpandProperty Free)/1gb),2) 50 | # 51 | # I use GIT now for most everything and this allows my prompt to have nifty colors that represent 52 | # the status of various files 53 | # 54 | # $Host.UI.RawUI.ForegroundColor = $GitPromptSettings.DefaultForegroundColor 55 | Write-Host "# $($env:username)@$($env:computername) | $($Now) | [$($FreeSpace)GB] $(Get-Location) $Global:Admin " -NoNewLine 56 | # 57 | # This writes the actual status of the repo (if i'm in one) at the tail end of the cmdline 58 | # 59 | Write-VcsStatus 60 | # 61 | # The return is the bit that removes the PS> 62 | # 63 | return "`n" 64 | } -------------------------------------------------------------------------------- /vbs/playground/procedures/MapObjects.txt: -------------------------------------------------------------------------------- 1 | Sub MapObject(strURL, strDriveLetter) 2 | On Error Resume Next 3 | Dim strNetBios 4 | Dim objNetwork 5 | ' 6 | ' Map an object in AD based on its UNCName property 7 | ' 8 | ' Printers are connected to \\ps 9 | ' Folders are connected to \\soecs-fs 10 | ' 11 | ' This script needs to catch the username 12 | ' 13 | strNetBios = Left(strURL, InStr(strUrl, ".") - 1) 14 | Set objNetwork = CreateObject("Wscript.Network") 15 | 16 | Select Case strNetBios 17 | Case "\\ps" 18 | If InStr(strURL, "laser") Then 19 | objNetwork.AddWindowsPrinterConnection strURL 20 | If Err <> 0 Then 21 | Call LogData(1, Err.Number & vbCrLf & Err.Description) 22 | Err.Clear 23 | Else 24 | Call LogData(4, "Mapping printer: " & strURL) 25 | End If 26 | objNetwork.SetDefaultPrinter strURL 27 | If Err <> 0 Then 28 | Call LogData(1, Err.Number & vbCrLf & Err.Description) 29 | Err.Clear 30 | Else 31 | Call LogData(4, "Default printer: " & strURL) 32 | End If 33 | Else 34 | objNetwork.AddWindowsPrinterConnection strURL 35 | If Err <> 0 Then 36 | Call LogData(1, Err.Number & vbCrLf & Err.Description) 37 | Err.Clear 38 | Else 39 | Call LogData(4, "Mapping printer: " & strURL) 40 | End If 41 | End If 42 | Case "\\fs" 43 | objNetwork.MapNetworkDrive strDriveLetter, strURL 44 | If Err <> 0 Then 45 | Call LogData(1, "Unable to map the following resource:" & vbCrLf & strURL & vbCrLf & Err.Number & vbCrLf & Err.Description) 46 | Err.Clear 47 | Else 48 | Call LogData(4, "Mapping drive " & strDriveLetter) 49 | End If 50 | Case "\\people" 51 | objNetwork.MapNetworkDrive strDriveLetter, strURL & "\" & RetrieveUser() 52 | If Err <> 0 Then 53 | Call LogData(1, "Unable to map the following resource:" & vbCrLf & strURL & vbCrLf & Err.Number & vbCrLf & Err.Description) 54 | Err.Clear 55 | Else 56 | Call LogData(4, "Mapping drive " & strDriveLetter) 57 | End If 58 | Case Else 59 | Call LogData(2, "Unable to map the following resource:" & vbCrLf & strURL) 60 | End Select 61 | 62 | End Sub -------------------------------------------------------------------------------- /vbs/playground/ListSerials.vbs: -------------------------------------------------------------------------------- 1 | Option Explicit 2 | 3 | Call QueryAD("SELECT DistinguishedName ,Name FROM 'LDAP://OU=Servers,DC=company,DC=com' WHERE objectClass = 'computer'") 4 | 5 | Sub QueryAD(strQuery) 6 | On Error Resume Next 7 | ' 8 | ' This procedure will loop through a recordset of objects 9 | ' returned from a query. 10 | ' 11 | Const ADS_SCOPE_SUBTREE = 2 12 | Dim objConnection 13 | Dim objCommand 14 | Dim objRecordset 15 | 16 | Set objConnection = CreateObject("ADODB.Connection") 17 | Set objCommand = CreateObject("ADODB.Command") 18 | objConnection.Provider = "ADsDSOObject" 19 | objConnection.Open "Active Directory Provider" 20 | 21 | Set objCOmmand.ActiveConnection = objConnection 22 | objCommand.CommandText = strQuery 23 | objCommand.Properties("Page Size") = 1000 24 | objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 25 | Set objRecordSet = objCommand.Execute 26 | If Err <> 0 Then Call LogData(1, "Unable to connect using the provided query: " & vbCrLf & strQuery) 27 | 28 | objRecordSet.MoveFirst 29 | 30 | Do Until objRecordSet.EOF 31 | Wscript.Echo objRecordSet.Fields("Name") & ".soecs.ku.edu" & ": " & GetSerial(objRecordSet.Fields("Name") & ".soecs.ku.edu") 32 | objRecordSet.MoveNext 33 | Loop 34 | End Sub 35 | 36 | Function GetSerial(strComputer) 37 | ' 38 | ' Get serial number from the BIOS 39 | ' 40 | Dim strSerial 41 | Dim objWMIService 42 | Dim colItems 43 | Dim objItem 44 | 45 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 46 | Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_BIOS",,48) 47 | 48 | For Each objItem in colItems 49 | strSerial = objItem.SerialNumber 50 | Next 51 | 52 | GetSerial = strSerial 53 | End Function 54 | 55 | Sub LogData(intCode, strMessage) 56 | ' Write data to application log 57 | ' 58 | ' http://www.microsoft.com/technet/scriptcenter/guide/default.mspx?mfr=true 59 | ' 60 | ' Event Codes 61 | ' 0 = Success 62 | ' 1 = Error 63 | ' 2 = Warning 64 | ' 4 = Information 65 | Dim objShell 66 | 67 | Set objShell = Wscript.CreateObject("Wscript.Shell") 68 | 69 | objShell.LogEvent intCode, strMessage 70 | 71 | End Sub -------------------------------------------------------------------------------- /vbs/playground/functions/GetInstalledSoftware.txt: -------------------------------------------------------------------------------- 1 | Sub GetInstalledSoftware(strComputer, blnSMSClient) 2 | ' 3 | ' Get installed software from computer 4 | ' 5 | ' There are two WMI classes that handle this: 6 | ' Win32Reg_AddRemovePrograms: only if the sms client installed 7 | ' Win32_Product: enabled by default on client computers not severs 8 | ' 9 | ' Taking the guess work out, I'll pass in whether or not 10 | ' the client is installed. Nothing fancy, just yes or no 11 | ' from the calling routine. 12 | ' 13 | Dim strSoftwareName 14 | Dim strIdentNum 15 | Dim strInstallDate 16 | Dim strVendor 17 | Dim strVersion 18 | Dim InstalledSoftware 19 | 20 | Dim objWMIService 21 | Dim colItems 22 | Dim objItem 23 | 24 | Select Case blnSMSClient 25 | Case vbYes 26 | InstalledSoftware = "" 27 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 28 | Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32Reg_AddRemovePrograms",,48) 29 | 30 | For Each objItem in colItems 31 | strSoftwareName = objItem.DisplayName 32 | strIdentNum = objItem.ProdID 33 | strInstallDate = objItem.InstallDate 34 | strVendor = objItem.Publisher 35 | strVersion = objItem.Version 36 | InstalledSoftware = InstalledSoftware & strSoftwareName & ", " & strIdentNum & ", " & strInstallDate & ", " & strVendor & ", " & strVersion & vbCrLf 37 | Next 38 | Case vbNo 39 | InstalledSoftware = "" 40 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 41 | ' 42 | ' There is a thing about InstallDate, may need to use InstallDate2 43 | ' 44 | Set colItems = objWMIService.ExecQuery("SELECT Name, IdentifyingNumber, InstallDate, Vendor, Version FROM Win32_Product",,48) 45 | 46 | For Each objItem in colItems 47 | strSoftwareName = objItem.Name 48 | strIdentNum = objItem.IdentifyingNumber 49 | strInstallDate = objItem.InstallDate 50 | strVendor = objItem.Vendor 51 | strVersion = objItem.Version 52 | InstalledSoftware = InstalledSoftware & strSoftwareName & ", " & strIdentNum & ", " & strInstallDate & ", " & strVendor & ", " & strVersion & vbCrLf 53 | Next 54 | Case Else 55 | End Select 56 | 57 | End Sub -------------------------------------------------------------------------------- /powershell/playground/mlbData.ps1: -------------------------------------------------------------------------------- 1 | param ( 2 | $Date= (Get-Date).AddDays(-1), 3 | $Database = 'masterscoreboard', 4 | $ServerName = 'gd2mlb', 5 | $Username = 'jspatton', 6 | $Password = 'Natalie1N^msjc4d' 7 | ) 8 | $Year = (Get-Date($Date) -Format yyy); 9 | $Month = (Get-Date($Date) -Format MM); 10 | $Day = (Get-Date($Date) -Format dd); 11 | $ServerInstance = "$($ServerName).database.windows.net" 12 | 13 | $url = "http://gd2.mlb.com/components/game/mlb/year_$($Year)/month_$($Month)/day_$($Day)/master_scoreboard.json"; 14 | $Data = Invoke-WebRequest -Uri $url |Select-Object -ExpandProperty Content |ConvertFrom-Json; 15 | # 16 | # Add games to season 17 | # 18 | $ColumnNames = $Data.data.games.game[0] |Get-Member -Type NoteProperty |Select-Object -Property Name |ForEach-Object {$Property = $_.Name;if ($Data.data.games.game[0].$Property.GetType().Name -ne 'PSCustomObject'){$_.Name}}; 19 | foreach ($Game in $Data.data.games.game) { 20 | $TableData = "INSERT INTO mlb_$($Year)_masterScoreboard ("; 21 | foreach ($ColumnName in ($ColumnNames |Sort-Object)){$TableData += "f_$($ColumnName),"}; 22 | $TableData += "f_away_team_runs,f_home_team_runs,f_away_team_hits,f_home_team_hits,f_away_team_errors,f_home_team_errors,f_away_team_sb,f_home_team_sb,f_away_team_so,f_home_team_so)"; 23 | $TableData += " VALUES ("; 24 | foreach ($ColumnName in ($ColumnNames |Sort-Object)){$TableData += "`'$($game.$ColumnName)`',"}; 25 | $TableData += "`'$($game.linescore.r.away)`',`'$($game.linescore.r.home)`',`'$($game.linescore.h.away)`',`'$($game.linescore.h.home)`',`'$($game.linescore.e.away)`',`'$($game.linescore.e.home)`',`'$($game.linescore.sb.away)`',`'$($game.linescore.sb.home)`',`'$($game.linescore.so.away)`',`'$($game.linescore.so.home)`')"; 26 | Invoke-Sqlcmd -Database $Database -ServerInstance $ServerInstance -Username $Username -Password $Password -OutputSqlErrors $True -Query $TableData; 27 | 28 | foreach ($Inning in $game.linescore.inning) { 29 | $TableData = "INSERT INTO mlb_$($Year)_innings ("; 30 | $TableData +="f_id, f_away, f_home)" 31 | $TableData += " VALUES (" 32 | $TableData += "`'$($game.id)`',`'$($Inning.away)`',`'$($Inning.home)`')" 33 | 34 | Invoke-Sqlcmd -Database $Database -ServerInstance $ServerInstance -Username $Username -Password $Password -OutputSqlErrors $True -Query $TableData; 35 | } 36 | } -------------------------------------------------------------------------------- /wiki/GetFreeDiskSpace.wiki: -------------------------------------------------------------------------------- 1 | = !Get-FreeDiskSpace.ps1 = 2 | {{{ 3 | 4 | NAME 5 | C:\mod-posh\powershell\production\Get-FreeDiskSpace.ps1 6 | 7 | SYNOPSIS 8 | Return free space on disk 9 | 10 | SYNTAX 11 | C:\mod-posh\powershell\production\Get-FreeDiskSpace.ps1 [[-FileName] ] [] 13 | 14 | 15 | DESCRIPTION 16 | This script works in conjunction with an Event Trigger on the System 17 | event on our file servers. This script queries the System log for 18 | EventID 2013, and returns the drive letter from the most recent 19 | event. 20 | 21 | This should be the same event that triggered this script to 22 | run in the first place. 23 | 24 | It outputs an XML file to the StorageReports directory which exists 25 | on both nodes of the file server cluster. 26 | 27 | 28 | PARAMETERS 29 | -FileName 30 | The fully qualified path and filename for the report. 31 | 32 | Required? false 33 | Position? 1 34 | Default value 35 | Accept pipeline input? false 36 | Accept wildcard characters? 37 | 38 | 39 | This cmdlet supports the common parameters: Verbose, Debug, 40 | ErrorAction, ErrorVariable, WarningAction, WarningVariable, 41 | OutBuffer and OutVariable. For more information, type, 42 | "get-help about_commonparameters". 43 | 44 | INPUTS 45 | 46 | OUTPUTS 47 | 48 | NOTES 49 | 50 | 51 | ScriptName: Get-FreeDiskSpace.ps1 52 | Created By: Jeff Patton 53 | Date Coded: July 12, 2011 54 | ScriptName is used to register events for this script 55 | LogName is used to determine which classic log to write to 56 | 57 | -------------------------- EXAMPLE 1 -------------------------- 58 | 59 | C:\PS>Get-FreeDiskSpace.ps1 60 | 61 | 62 | Description 63 | ----------- 64 | This is the only syntax for this script. 65 | 66 | 67 | 68 | 69 | 70 | 71 | RELATED LINKS 72 | https://code.google.com/p/mod-posh/wiki/Get-FreeDiskSpace 73 | 74 | 75 | 76 | }}} 77 | -------------------------------------------------------------------------------- /wiki/NewPrintJob.wiki: -------------------------------------------------------------------------------- 1 | = !New-PrintJob.ps1 = 2 | {{{ 3 | 4 | NAME 5 | C:\mod-posh\powershell\production\New-PrintJob.ps1 6 | 7 | SYNOPSIS 8 | Log a print job to a file. 9 | 10 | SYNTAX 11 | C:\mod-posh\powershell\production\New-PrintJob.ps1 [[-FileName] ] [] 12 | 13 | 14 | DESCRIPTION 15 | This script works in conjunction with an Event Trigger on the PrintService 16 | event on our print servers. This script queries the Microsoft-Windows-PrintService/Operational 17 | log for EventID 307, and returns the drive letter from the most recent event. 18 | 19 | This should be the same event that triggered this script to 20 | run in the first place. 21 | 22 | It appends to a CSV log file if it exists, or creates a new file if it doesn't. 23 | 24 | 25 | PARAMETERS 26 | -FileName 27 | The fully qualified path and filename for the report. 28 | 29 | Required? false 30 | Position? 1 31 | Default value 32 | Accept pipeline input? false 33 | Accept wildcard characters? 34 | 35 | 36 | This cmdlet supports the common parameters: Verbose, Debug, 37 | ErrorAction, ErrorVariable, WarningAction, WarningVariable, 38 | OutBuffer and OutVariable. For more information, type, 39 | "get-help about_commonparameters". 40 | 41 | INPUTS 42 | 43 | OUTPUTS 44 | 45 | NOTES 46 | 47 | 48 | ScriptName: New-PrintJob.ps1 49 | Created By: Jeff Patton 50 | Date Coded: August 17, 2011 51 | ScriptName is used to register events for this script 52 | LogName is used to determine which classic log to write to 53 | Microsoft .NET Framework 3.5 or greater is required. 54 | 55 | -------------------------- EXAMPLE 1 -------------------------- 56 | 57 | C:\PS>.\New-PrintJob.ps1 58 | 59 | 60 | Description 61 | ----------- 62 | This is the only syntax for this script. 63 | 64 | 65 | 66 | 67 | 68 | 69 | RELATED LINKS 70 | https://code.google.com/p/mod-posh/wiki/New-PrintJob 71 | 72 | 73 | 74 | }}} 75 | -------------------------------------------------------------------------------- /wiki/FindLocalAdmins.wiki: -------------------------------------------------------------------------------- 1 | = !Find-LocalAdmins.ps1 = 2 | {{{ 3 | 4 | NAME 5 | C:\mod-posh\powershell\production\Find-LocalAdmins.ps1 6 | 7 | SYNOPSIS 8 | List users in specified local group 9 | 10 | SYNTAX 11 | C:\mod-posh\powershell\production\Find-LocalAdmins.ps1 [-ADSPath] [-GroupName] [] 13 | 14 | 15 | DESCRIPTION 16 | Created: March 17, 2011 Jeff Patton 17 | This script searches ActiveDirectory for computers. It then queries each computer for the list 18 | of users who 19 | are in the local Administrators group. 20 | 21 | 22 | PARAMETERS 23 | -ADSPath 24 | The LDAP URI of the container you wish to pull computers from. 25 | 26 | Required? true 27 | Position? 1 28 | Default value 29 | Accept pipeline input? false 30 | Accept wildcard characters? 31 | 32 | -GroupName 33 | The name of the local group to pull membership pfrom. 34 | 35 | Required? true 36 | Position? 2 37 | Default value 38 | Accept pipeline input? false 39 | Accept wildcard characters? 40 | 41 | 42 | This cmdlet supports the common parameters: Verbose, Debug, 43 | ErrorAction, ErrorVariable, WarningAction, WarningVariable, 44 | OutBuffer and OutVariable. For more information, type, 45 | "get-help about_commonparameters". 46 | 47 | INPUTS 48 | 49 | OUTPUTS 50 | 51 | NOTES 52 | 53 | 54 | You will need to run this script as an administrator or disable UAC to update the event-log 55 | You will need to have at least Read permissions in the AD container in order to get a list 56 | of computers. 57 | 58 | -------------------------- EXAMPLE 1 -------------------------- 59 | 60 | C:\PS>find-localadmins "LDAP://OU=Workstations,DC=company,DC=com" 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | RELATED LINKS 71 | https://code.google.com/p/mod-posh/wiki/FindLocalAdmins 72 | 73 | 74 | 75 | }}} 76 | -------------------------------------------------------------------------------- /vbs/playground/functions/GetWMIData.txt: -------------------------------------------------------------------------------- 1 | Function GetWMIData(strComputer, WMIClass, WMIProperty) 2 | ' 3 | ' This function replaces more or less any WMI Call 4 | ' that returns a single value. You could potentially 5 | ' tweak it to handle more complicated returns like 6 | ' IPAddress. 7 | ' 8 | ' The function is passed three arguments: 9 | ' strComputer = Computer to run WMI call against 10 | ' WMIClass = The WMI Class that we're querying 11 | ' WMIProperty = The WMI property that we're looking for 12 | ' 13 | Dim objWMIService 14 | Dim colItems 15 | Dim objItem 16 | Dim strReturnVal 17 | 18 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 19 | If Err <> 0 Then 20 | Call HandleError(Err.Number, Err.Description) 21 | End If 22 | Set colItems = objWMIService.ExecQuery("SELECT " & WMIProperty & " FROM " & WMIClass,,48) 23 | If Err <> 0 Then 24 | Call HandleError(Err.Number, Err.Description) 25 | End If 26 | 27 | For Each objItem In colItems 28 | Select Case lcase(WMIProperty) 29 | Case "caption" 30 | strReturnVal = objItem.Caption 31 | Case "csdversion" 32 | strReturnVal = objItem.CSDVersion 33 | If isNull(strReturnVal) Then strReturnVal = "" 34 | Case "serialnumber" 35 | strReturnVal = objItem.SerialNumber 36 | Case "dnshostname" 37 | strReturnVal = objItem.DNSHostName 38 | Case "csname" 39 | strReturnVal = objItem.CSName 40 | Case "uuid" 41 | strReturnVal = objItem.UUID 42 | Case "identifyingnumber" 43 | strReturnVal = objItem.IdentifyingNumber 44 | Case "name" 45 | strReturnVal = objItem.Name 46 | Case "vendor" 47 | strReturnVal = objItem.Vendor 48 | Case "systemdrive" 49 | strReturnVal = objItem.SystemDrive 50 | Case "totalvisiblememorysize" 51 | strReturnVal = objItem.TotalVisibleMemorySize 52 | Case "numberofcores" 53 | strReturnVal = objItem.NumberOfCores 54 | Case "lastbootuptime" 55 | strReturnVal = objItem.LastBootUpTime 56 | Case "currentclockspeed" 57 | strReturnVal = objItem.CurrentClockSpeed 58 | Case Else 59 | Call LogData(1, "Unable to find " & WMIProperty & " in " & WMIClass & vbCrLf & "Please submit a ticket at http://code.patton-tech.com/winmon/newticket") 60 | End Select 61 | Next 62 | 63 | GetWMIData = strReturnVal 64 | End Function 65 | -------------------------------------------------------------------------------- /vbs/playground/ChasisTypeScript.vbs: -------------------------------------------------------------------------------- 1 | Dim intHit 2 | 3 | Call QueryAD("SELECT DistinguishedName ,Name FROM 'LDAP://DC=company,DC=com' WHERE objectClass = 'computer'") 4 | 5 | Wscript.Echo "Found " & intHit 6 | 7 | Sub BatteryPresent(strComputer) 8 | ' 9 | ' This function needs to return false in order to prevent GPO application 10 | ' 11 | Dim objWMIService 12 | Dim colItems 13 | Dim objItem 14 | 15 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 16 | Set colItems = objWMIService.ExecQuery( _ 17 | "SELECT * FROM Win32_PortableBattery",,48) 18 | For Each objItem in colItems 19 | Wscript.Echo "-----------------------------------" 20 | Wscript.Echo strComputer 21 | Wscript.Echo "-----------------------------------" 22 | Wscript.Echo "Caption: " & objItem.Caption 23 | Next 24 | 25 | intHit = intHit + 1 26 | 27 | End Sub 28 | 29 | Sub QueryAD(strQuery) 30 | On Error Resume Next 31 | ' 32 | ' This procedure will loop through a recordset of objects 33 | ' returned from a query. 34 | ' 35 | Const ADS_SCOPE_SUBTREE = 2 36 | Dim objConnection 37 | Dim objCommand 38 | Dim objRecordset 39 | 40 | Set objConnection = CreateObject("ADODB.Connection") 41 | Set objCommand = CreateObject("ADODB.Command") 42 | objConnection.Provider = "ADsDSOObject" 43 | objConnection.Open "Active Directory Provider" 44 | 45 | Set objCOmmand.ActiveConnection = objConnection 46 | objCommand.CommandText = strQuery 47 | objCommand.Properties("Page Size") = 1000 48 | objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 49 | Set objRecordSet = objCommand.Execute 50 | If Err <> 0 Then Call LogData(1, "Unable to connect using the provided query: " & vbCrLf & strQuery) 51 | 52 | objRecordSet.MoveFirst 53 | 54 | Do Until objRecordSet.EOF 55 | ' 56 | ' Code to do whatever is needed 57 | ' 58 | Call BatteryPresent(objRecordset.Fields("Name")) 59 | objRecordSet.MoveNext 60 | Loop 61 | End Sub 62 | 63 | Sub LogData(intCode, strMessage) 64 | ' Write data to application log 65 | ' 66 | ' http://www.microsoft.com/technet/scriptcenter/guide/default.mspx?mfr=true 67 | ' 68 | ' Event Codes 69 | ' 0 = Success 70 | ' 1 = Error 71 | ' 2 = Warning 72 | ' 4 = Information 73 | Dim objShell 74 | 75 | Set objShell = Wscript.CreateObject("Wscript.Shell") 76 | 77 | objShell.LogEvent intCode, strMessage 78 | 79 | End Sub -------------------------------------------------------------------------------- /wiki/createsite.wiki: -------------------------------------------------------------------------------- 1 | = !create-site.ps1 = 2 | {{{ 3 | 4 | NAME 5 | C:\mod-posh\powershell\production\create-site.ps1 6 | 7 | SYNOPSIS 8 | Create a new SharePoint site within a new SQL DB 9 | 10 | SYNTAX 11 | C:\mod-posh\powershell\production\create-site.ps1 [-RootURL] [-SitePath] [] 13 | 14 | 15 | DESCRIPTION 16 | Created March 8, 2011: Jeff Patton 17 | This script creates a new SharePoint site within a new SQL DB. It relies on several functions i 18 | nside the 19 | SharePointManagement.ps1 library to work properly. You will need to provide the base URL of you 20 | r SharePoint 21 | installation as well as the path to the new site to be created. 22 | 23 | 24 | PARAMETERS 25 | -RootURL 26 | This is the base URL of your WSS 3.0 installation 27 | 28 | Required? true 29 | Position? 1 30 | Default value 31 | Accept pipeline input? false 32 | Accept wildcard characters? 33 | 34 | -SitePath 35 | This is the path to your new WSS 3.0 site 36 | 37 | Required? true 38 | Position? 2 39 | Default value 40 | Accept pipeline input? false 41 | Accept wildcard characters? 42 | 43 | 44 | This cmdlet supports the common parameters: Verbose, Debug, 45 | ErrorAction, ErrorVariable, WarningAction, WarningVariable, 46 | OutBuffer and OutVariable. For more information, type, 47 | "get-help about_commonparameters". 48 | 49 | INPUTS 50 | 51 | OUTPUTS 52 | 53 | NOTES 54 | 55 | 56 | Run script from Sharepoint server 57 | Run script as Administrator or disable UAC 58 | Script needs to be run under a SharePoint Farm Administrator account 59 | 60 | -------------------------- EXAMPLE 1 -------------------------- 61 | 62 | C:\PS>create-site http://intranet.company.com team 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | RELATED LINKS 73 | https://code.google.com/p/mod-posh/wiki/create-site 74 | 75 | 76 | 77 | }}} 78 | -------------------------------------------------------------------------------- /wiki/GetOutageDuration.wiki: -------------------------------------------------------------------------------- 1 | = !Get-OutageDuration.ps1 = 2 | {{{ 3 | 4 | NAME 5 | C:\mod-posh\powershell\production\Get-OutageDuration.ps1 6 | 7 | SYNOPSIS 8 | Returns the length of time a server was offline. 9 | 10 | SYNTAX 11 | C:\mod-posh\powershell\production\Get-OutageDuration.ps1 [[-FileName] ] [] 13 | 14 | 15 | DESCRIPTION 16 | This script works in conjunction with an Event Trigger on the System 17 | event. This script queries the System log for EventID 11, and returns 18 | when the computer went offline, when it came back online and how long 19 | it was unavailable. 20 | 21 | It outputs an XML file to the Reports directory which it creates if 22 | it doesn't exist already. 23 | 24 | 25 | PARAMETERS 26 | -FileName 27 | The fully qualified path and filename for the report. 28 | 29 | Required? false 30 | Position? 1 31 | Default value 32 | Accept pipeline input? false 33 | Accept wildcard characters? 34 | 35 | 36 | This cmdlet supports the common parameters: Verbose, Debug, 37 | ErrorAction, ErrorVariable, WarningAction, WarningVariable, 38 | OutBuffer and OutVariable. For more information, type, 39 | "get-help about_commonparameters". 40 | 41 | INPUTS 42 | 43 | OUTPUTS 44 | 45 | NOTES 46 | 47 | 48 | ScriptName : Get-OutageDuration.ps1 49 | Created By : jeffpatton.admin 50 | Date Coded : 10/26/2011 17:12:21 51 | ScriptName is used to register events for this script 52 | LogName is used to determine which classic log to write to 53 | 54 | ErrorCodes 55 | 100 = Success 56 | 101 = Error 57 | 102 = Warning 58 | 104 = Information 59 | 60 | -------------------------- EXAMPLE 1 -------------------------- 61 | 62 | C:\PS>Get-OutageDuration.ps1 63 | 64 | 65 | Description 66 | ----------- 67 | This is the only syntax for this script. 68 | 69 | 70 | 71 | 72 | 73 | 74 | RELATED LINKS 75 | https://code.google.com/p/mod-posh/wiki/Get-OutageDuration.ps1 76 | 77 | 78 | 79 | }}} 80 | -------------------------------------------------------------------------------- /vbs/playground/BatteryScript.vbs: -------------------------------------------------------------------------------- 1 | Dim intMiss 2 | Dim intHit 3 | 4 | Call QueryAD("SELECT DistinguishedName ,Name FROM 'LDAP://OU=Computers,OU=SOEDO,DC=company,DC=com' WHERE objectClass = 'computer'") 5 | Wscript.Echo "Found " & intHit 6 | Wscript.Echo "Skipped " & intMiss 7 | Wscript.Echo "Total " & intHit + intMiss 8 | 9 | Sub BatteryPresent(strComputer) 10 | Dim objWMIService 11 | Dim colItems 12 | Dim objItem 13 | 14 | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 15 | ' Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Battery",,48) 16 | Set colItems = objWMIService.ExecQuery("SELECT * FROMWin32_PortableBattery",,48) 17 | 18 | For Each objItem in colItems 19 | If objItem.Caption = "" Then 20 | intMiss = intMiss + 1 21 | Exit For 22 | Else 23 | Wscript.Echo strComputer & ": " & objItem.Caption 24 | intHit = intHit + 1 25 | End If 26 | Next 27 | End Sub 28 | 29 | Sub QueryAD(strQuery) 30 | On Error Resume Next 31 | ' 32 | ' This procedure will loop through a recordset of objects 33 | ' returned from a query. 34 | ' 35 | Const ADS_SCOPE_SUBTREE = 2 36 | Dim objConnection 37 | Dim objCommand 38 | Dim objRecordset 39 | 40 | Set objConnection = CreateObject("ADODB.Connection") 41 | Set objCommand = CreateObject("ADODB.Command") 42 | objConnection.Provider = "ADsDSOObject" 43 | objConnection.Open "Active Directory Provider" 44 | 45 | Set objCOmmand.ActiveConnection = objConnection 46 | objCommand.CommandText = strQuery 47 | objCommand.Properties("Page Size") = 1000 48 | objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 49 | Set objRecordSet = objCommand.Execute 50 | If Err <> 0 Then Call LogData(1, "Unable to connect using the provided query: " & vbCrLf & strQuery) 51 | 52 | objRecordSet.MoveFirst 53 | 54 | Do Until objRecordSet.EOF 55 | ' 56 | ' Code to do whatever is needed 57 | ' 58 | Call BatteryPresent(objRecordset.Fields("Name")) 59 | objRecordSet.MoveNext 60 | Loop 61 | End Sub 62 | 63 | Sub LogData(intCode, strMessage) 64 | ' Write data to application log 65 | ' 66 | ' http://www.microsoft.com/technet/scriptcenter/guide/default.mspx?mfr=true 67 | ' 68 | ' Event Codes 69 | ' 0 = Success 70 | ' 1 = Error 71 | ' 2 = Warning 72 | ' 4 = Information 73 | Dim objShell 74 | 75 | Set objShell = Wscript.CreateObject("Wscript.Shell") 76 | 77 | objShell.LogEvent intCode, strMessage 78 | 79 | End Sub -------------------------------------------------------------------------------- /powershell/playground/Get-EmptyUnlinkedGPO.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Template script 4 | .DESCRIPTION 5 | This script sets up the basic framework that I use for all my scripts. 6 | .PARAMETER 7 | .EXAMPLE 8 | .NOTES 9 | ScriptName : Get-EmptyUnlinkedGPO.ps1 10 | Created By : jspatton 11 | Date Coded : 09/11/2013 09:16:51 12 | ScriptName is used to register events for this script 13 | 14 | ErrorCodes 15 | 100 = Success 16 | 101 = Error 17 | 102 = Warning 18 | 104 = Information 19 | .LINK 20 | https://code.google.com/p/mod-posh/wiki/Production/Get-EmptyUnlinkedGPO.ps1 21 | #> 22 | [CmdletBinding()] 23 | Param 24 | ( 25 | ) 26 | Begin 27 | { 28 | $ScriptName = $MyInvocation.MyCommand.ToString() 29 | $ScriptPath = $MyInvocation.MyCommand.Path 30 | $Username = $env:USERDOMAIN + "\" + $env:USERNAME 31 | 32 | New-EventLog -Source $ScriptName -LogName 'Windows Powershell' -ErrorAction SilentlyContinue 33 | 34 | $Message = "Script: " + $ScriptPath + "`nScript User: " + $Username + "`nStarted: " + (Get-Date).toString() 35 | Write-EventLog -LogName 'Windows Powershell' -Source $ScriptName -EventID "104" -EntryType "Information" -Message $Message 36 | 37 | # Dotsource in the functions you need. 38 | try 39 | { 40 | Import-Module GroupPolicy 41 | Import-Module C:\powershell\Production\includes\ActiveDirectoryManagement.psm1 42 | } 43 | catch 44 | { 45 | Write-Error $Error[0] 46 | break 47 | } 48 | } 49 | Process 50 | { 51 | foreach ($Gpo in (Get-GPO -All)) 52 | { 53 | if ($Gpo.Computer.DSVersion -eq 0 -and $Gpo.User.DSVersion -eq 0) 54 | { 55 | $Links = Get-GpoLink -Gpo $Gpo.Id.Guid 56 | if (!($Links)) 57 | { 58 | $Gpo.DisplayName 59 | } 60 | } 61 | } 62 | } 63 | End 64 | { 65 | $Message = "Script: " + $ScriptPath + "`nScript User: " + $Username + "`nFinished: " + (Get-Date).toString() 66 | Write-EventLog -LogName 'Windows Powershell' -Source $ScriptName -EventID "104" -EntryType "Information" -Message $Message 67 | } -------------------------------------------------------------------------------- /vbs/playground/procedures/BuildArray.txt: -------------------------------------------------------------------------------- 1 | Sub BuildArray(strLDAP, strObject) 2 | ' 3 | ' Build an array of Active Directory Objects 4 | ' using the supplied LDAP URL and object for the query. 5 | ' 6 | Const ADS_SCOPE_SUBTREE = 2 7 | Dim objConnection 8 | Dim objCommand 9 | Dim objRecordset 10 | 11 | Set objConnection = CreateObject("ADODB.Connection") 12 | Set objCommand = CreateObject("ADODB.Command") 13 | objConnection.Provider = "ADsDSOObject" 14 | objConnection.Open "Active Directory Provider" 15 | 16 | Set objCOmmand.ActiveConnection = objConnection 17 | objCommand.CommandText = "SELECT DistinguishedName, Name FROM '" & strLDAP & "' WHERE objectClass='" & strObject & "'" 18 | objCommand.Properties("Page Size") = 1000 19 | objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 20 | Set objRecordSet = objCommand.Execute 21 | 22 | objRecordSet.MoveFirst 23 | 24 | Do Until objRecordSet.EOF 25 | If InStr(objRecordSet.Fields("DistinguishedName").Value, "1005") Then 26 | Call UpdateArray(objRecordSet.Fields("DistinguishedName").Value, 0, "Eaton 1005") 27 | End If 28 | If InStr(objRecordSet.Fields("DistinguishedName").Value, "1014") Then 29 | Call UpdateArray(objRecordSet.Fields("DistinguishedName").Value, 1, "Eaton 1014") 30 | End If 31 | If InStr(objRecordSet.Fields("DistinguishedName").Value, "1018") Then 32 | Call UpdateArray(objRecordSet.Fields("DistinguishedName").Value, 2, "Eaton 1018") 33 | End If 34 | If InStr(objRecordSet.Fields("DistinguishedName").Value, "1137") Then 35 | Call UpdateArray(objRecordSet.Fields("DistinguishedName").Value, 3, "Learned 1137") 36 | End If 37 | If InStr(objRecordSet.Fields("DistinguishedName").Value, "1170") Then 38 | Call UpdateArray(objRecordSet.Fields("DistinguishedName").Value, 4, "Learned 1170") 39 | End If 40 | If InStr(objRecordSet.Fields("DistinguishedName").Value, "1171") Then 41 | Call UpdateArray(objRecordSet.Fields("DistinguishedName").Value, 5, "Learned 1171") 42 | End If 43 | If InStr(objRecordSet.Fields("DistinguishedName").Value, "3101") Then 44 | Call UpdateArray(objRecordSet.Fields("DistinguishedName").Value, 6, "Learned 3101") 45 | End If 46 | If InStr(objRecordSet.Fields("DistinguishedName").Value, "3117") Then 47 | Call UpdateArray(objRecordSet.Fields("DistinguishedName").Value, 7, "Learned 3117") 48 | End If 49 | objRecordSet.MoveNext 50 | Loop 51 | End Sub -------------------------------------------------------------------------------- /powershell/playground/Setup-Retrosheet.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | Setup Retrosheet folder structure and grab chadwick files 3 | from 4 | #> 5 | try 6 | { 7 | $ChadwickUrl = 'http://softlayer-dal.dl.sourceforge.net/project/chadwick/chadwick-0.6/chadwick-0.6.4/chadwick-0.6.4.zip' 8 | $7zipPath = 'C:\Program Files\7-Zip\7z.exe' 9 | 10 | New-Item C:\Retrosheet -ItemType Directory 11 | New-Item C:\Retrosheet\Common -ItemType Directory 12 | New-Item C:\Retrosheet\Common\PowerShell -ItemType Directory 13 | New-Item C:\Retrosheet\Common\Programs -ItemType Directory 14 | New-Item C:\Retrosheet\Common\Reports -ItemType Directory 15 | New-Item C:\Retrosheet\Common\SQL -ItemType Directory 16 | New-Item C:\Retrosheet\Common\Utilities -ItemType Directory 17 | New-Item C:\Retrosheet\Data -ItemType Directory 18 | New-Item C:\Retrosheet\Data\Parsed -ItemType Directory 19 | New-Item C:\Retrosheet\Data\Parsed\Games -ItemType Directory 20 | New-Item C:\Retrosheet\Data\Parsed\Subs -ItemType Directory 21 | New-Item C:\Retrosheet\Data\Parsed\Events -ItemType Directory 22 | New-Item C:\Retrosheet\Data\UnZipped -ItemType Directory 23 | New-Item C:\Retrosheet\Data\Zipped -ItemType Directory 24 | New-Item C:\Retrosheet\DBMS -ItemType Directory 25 | New-Item C:\Retrosheet\DBMS\Azure -ItemType Directory 26 | 27 | Invoke-WebRequest -Uri $ChadwickUrl -OutFile C:\Retrosheet\Common\Programs\chadwick.zip 28 | Invoke-Expression -Command "& '$($7zipPath)' e C:\Retrosheet\Common\Programs\chadwick.zip -y -oC:\Retrosheet\Common\Programs"; 29 | Invoke-WebRequest -Uri https://raw.githubusercontent.com/jeffpatton1971/mod-posh/master/powershell/production/includes/RsModule.psm1 -OutFile C:\Retrosheet\Common\PowerShell\RsModule.psm1 30 | Invoke-WebRequest -Uri https://raw.githubusercontent.com/jeffpatton1971/mod-posh/master/powershell/playground/Start-RSDataProcessing.ps1 -OutFile C:\Retrosheet\Common\PowerShell\Start-RSDataProcessing.ps1 31 | Invoke-WebRequest -Uri https://gist.githubusercontent.com/jeffpatton1971/ee2ed12189506ccae173/raw/d84e3d016f4327a80326c15839e7825d99b23362/retrosheet_zip_files.TXT -OutFile C:\Retrosheet\Data\Zipped\retrosheet_zip_files.TXT 32 | 33 | $Global:RSPath = 'C:\Retrosheet'; 34 | $Global:RSDataPath = "$($Global:RSPath)\Data"; 35 | Write-Host "Launch C:\Retrosheet\Common\PowerShell\Start-RSDataProcessing.ps1 to begin setting up RetroSheet datafiles." 36 | } 37 | catch 38 | { 39 | throw $Error[0] 40 | } -------------------------------------------------------------------------------- /wiki/GetDHCPDenies.wiki: -------------------------------------------------------------------------------- 1 | = !Get-DHCPDenies.ps1 = 2 | {{{ 3 | 4 | NAME 5 | C:\mod-posh\powershell\production\Get-DHCPDenies.ps1 6 | 7 | SYNOPSIS 8 | Return host denied lease 9 | 10 | SYNTAX 11 | C:\mod-posh\powershell\production\Get-DHCPDenies.ps1 [-EventID] [] 12 | 13 | 14 | DESCRIPTION 15 | This script works in conjunction with an Event Trigger on the 16 | Microsoft-Windows-Dhcp-Server/FilterNotifications log on our 17 | DHCP server. This script queries the Microsoft-Windows-Dhcp-Server/FilterNotifications 18 | log for EventID 20097, and returns the MAC, Hostname, HardwareType, Time and Message 19 | of the event. 20 | 21 | This should be the same event that triggered this script to 22 | run in the first place. 23 | 24 | It outputs an XML file to the C:\LogFiles directory which exists on 25 | the server, if not it creates the folder. 26 | 27 | 28 | PARAMETERS 29 | -EventID 30 | 31 | Required? true 32 | Position? 1 33 | Default value 34 | Accept pipeline input? false 35 | Accept wildcard characters? 36 | 37 | 38 | This cmdlet supports the common parameters: Verbose, Debug, 39 | ErrorAction, ErrorVariable, WarningAction, WarningVariable, 40 | OutBuffer and OutVariable. For more information, type, 41 | "get-help about_commonparameters". 42 | 43 | INPUTS 44 | 45 | OUTPUTS 46 | 47 | NOTES 48 | 49 | 50 | ScriptName : Get-DHCPDenies.ps1 51 | Created By : jspatton 52 | Date Coded : 10/27/2011 09:26:54 53 | ScriptName is used to register events for this script 54 | LogName is used to determine which classic log to write to 55 | 56 | ErrorCodes 57 | 100 = Success 58 | 101 = Error 59 | 102 = Warning 60 | 104 = Information 61 | 62 | -------------------------- EXAMPLE 1 -------------------------- 63 | 64 | C:\PS>Get-DHCPDenies.ps1 65 | 66 | 67 | Description 68 | ----------- 69 | This is the only syntax for this script. 70 | 71 | 72 | 73 | 74 | 75 | 76 | RELATED LINKS 77 | https://code.google.com/p/mod-posh/wiki/GetDHCPDenies 78 | 79 | 80 | 81 | }}} 82 | -------------------------------------------------------------------------------- /powershell/playground/Sort-OldImages.ps1: -------------------------------------------------------------------------------- 1 | Set-Location 'C:\Users\jspatton\SkyDrive\Old Images' 2 | $Files = Get-ImagesFromWDS -LocalPath 'C:\Users\jspatton\SkyDrive\SkyDrive camera roll' 3 | $Images = $Files.Tables[0] 4 | $Lumia900 = @() 5 | $sghi917 = @() 6 | $sghi937 = @() 7 | foreach ($Image in $Images.Rows) 8 | { 9 | switch ($Image."SYSTEM.PHOTO.CAMERAMODEL") 10 | { 11 | "Nokia Lumia 900" 12 | { 13 | $Lumia900 += $Image 14 | } 15 | "SGH-I917" 16 | { 17 | $sghi917 += $Image 18 | } 19 | "SGH-i937" 20 | { 21 | $sghi937 += $Image 22 | } 23 | default 24 | { 25 | Move-Item $Image."SYSTEM.ITEMPATHDISPLAY" "$($PWD.Path)" 26 | } 27 | } 28 | } 29 | $Lumia900 = $Lumia900 |Sort-Object -Property "System.Photo.DateTaken" 30 | $sghi917 = $sghi917 |Sort-Object -Property "System.Photo.DateTaken" 31 | $sghi937 = $sghi937 |Sort-Object -Property "System.Photo.DateTaken" 32 | 33 | $Counter = 0 34 | foreach ($Image in $Lumia900) 35 | { 36 | $DestPath = $Image."SYSTEM.PHOTO.CAMERAMANUFACTURER" 37 | $SubFolder = $Image."SYSTEM.PHOTO.CAMERAMODEL" 38 | 39 | New-Item "$($PWD.Path)\$($DestPath)\$($SubFolder)" -ItemType Directory -Force |Out-Null 40 | $Filename = "WP_{0:D6}.jpg" -f $Counter 41 | 42 | Move-Item $Image."SYSTEM.ITEMPATHDISPLAY" "$($PWD.Path)\$($DestPath)\$($SubFolder)\$($Filename)" 43 | $Counter ++ 44 | } 45 | 46 | $Counter = 0 47 | foreach ($Image in $sghi917) 48 | { 49 | $DestPath = $Image."SYSTEM.PHOTO.CAMERAMANUFACTURER" 50 | $SubFolder = $Image."SYSTEM.PHOTO.CAMERAMODEL" 51 | 52 | New-Item "$($PWD.Path)\$($DestPath)\$($SubFolder)" -ItemType Directory -Force |Out-Null 53 | $Filename = "WP_{0:D6}.jpg" -f $Counter 54 | 55 | Move-Item $Image."SYSTEM.ITEMPATHDISPLAY" "$($PWD.Path)\$($DestPath)\$($SubFolder)\$($Filename)" 56 | $Counter ++ 57 | } 58 | 59 | $Counter = 0 60 | foreach ($Image in $sghi937) 61 | { 62 | $DestPath = $Image."SYSTEM.PHOTO.CAMERAMANUFACTURER" 63 | $DestPath = $Image."SYSTEM.PHOTO.CAMERAMANUFACTURER" 64 | $SubFolder = $Image."SYSTEM.PHOTO.CAMERAMODEL" 65 | 66 | New-Item "$($PWD.Path)\$($DestPath)\$($SubFolder)" -ItemType Directory -Force |Out-Null 67 | $Filename = "WP_{0:D6}.jpg" -f $Counter 68 | 69 | Move-Item $Image."SYSTEM.ITEMPATHDISPLAY" "$($PWD.Path)\$($DestPath)\$($SubFolder)\$($Filename)" 70 | $Counter ++ 71 | } -------------------------------------------------------------------------------- /PSMA/o365/New-Schema.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Schema for licensing AD users for Office365 4 | .DESCRIPTION 5 | This schema will setup Dirsycn with the proper objects and properties 6 | to provision or de-provision a user with an Office365 License. For details 7 | on how to setup your schema please see 8 | .NOTES 9 | ScriptName : New-Schema.ps1 10 | Created By : Jeffrey 11 | Date Coded : 12/29/2014 11:49:45 12 | 13 | This script is only run when a Management Agent is created or refreshed 14 | .LINK 15 | https://github.com/jeffpatton1971/mod-posh/wiki/Production/New-Schema.ps1 16 | .LINK 17 | http://blog.goverco.com/p/powershell-management-agent.html 18 | .LINK 19 | http://blog.goverco.com/p/psmaschema.html 20 | #> 21 | try 22 | { 23 | Import-Module C:\Scripts\LogFiles.psm1 24 | } 25 | catch 26 | { 27 | Write-Error $Error[0] 28 | break 29 | } 30 | try 31 | { 32 | $LogName = "PMA-Office365-Schema" 33 | $Source = "Setup" 34 | $EntryType = "Information" 35 | Write-LogFile -LogName $LogName -Source $Source -EventID 100 -EntryType $EntryType -Message "Setting up schema for use with dirsync" 36 | $obj = New-Object -TypeName psobject 37 | @( 38 | @{Name = "Anchor-id"; Type = "Binary"; Value = 1} 39 | @{Name = "objectClass"; Type = "String"; Value = "person"} 40 | @{Name = "objectguidstring"; Type = "String"; Value = ""} 41 | @{Name = "objectsidstring"; Type = "String"; Value = ""} 42 | @{Name = "sAMAccountName"; Type = "String"; Value = ""} 43 | @{Name = "msDS-cloudExtensionAttribute1"; Type = "String"; Value = ""} 44 | )| ForEach-Object { 45 | Write-LogFile -LogName $LogName -Source $Source -EventID 101 -EntryType $EntryType -Message "Adding $($_.Name)|$($_.Type) with Value $($_.Value) to the schema" 46 | $obj |Add-Member -MemberType NoteProperty -Name "$($_.Name)|$($_.Type)" -Value $_.Value 47 | } 48 | } 49 | catch 50 | { 51 | Write-LogFile -LogName $LogName -Source $Source -EventID 102 -EntryType "Error" -Message $Error[0].Exception 52 | break 53 | } 54 | if ($obj.'Anchor-id|Binary') 55 | { 56 | Write-LogFile -LogName $LogName -Source $Source -EventID 100 -EntryType $EntryType -Message "Setup complete" 57 | return $obj 58 | } 59 | else 60 | { 61 | Write-LogFile -LogName $LogName -Source $Source -EventID 102 -EntryType "Error" -Message "Object empty, please see earlier error message" 62 | } -------------------------------------------------------------------------------- /powershell/production/Get-BIOSReport.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Get-BIOSReport 4 | .DESCRIPTION 5 | This script walks AD and returns information about udating the BIOS 6 | .PARAMETER 7 | .EXAMPLE 8 | .NOTES 9 | ScriptName: 10 | Created By: Jeff Patton 11 | Date Coded: 12 | ScriptName is used to register events for this script 13 | LogName is used to determine which classic log to write to 14 | .LINK 15 | https://code.google.com/p/mod-posh/wiki/Get-BiosReport 16 | #> 17 | Param 18 | ( 19 | [parameter(Mandatory=$true, HelpMessage="Enter an LDAP url.")] 20 | $ADSPath 21 | ) 22 | Begin 23 | { 24 | $ScriptName = $MyInvocation.MyCommand.ToString() 25 | $LogName = "Application" 26 | $ScriptPath = $MyInvocation.MyCommand.Path 27 | $Username = $env:USERDOMAIN + "\" + $env:USERNAME 28 | 29 | New-EventLog -Source $ScriptName -LogName $LogName -ErrorAction SilentlyContinue 30 | 31 | $Message = "Script: " + $ScriptPath + "`nScript User: " + $Username + "`nStarted: " + (Get-Date).toString() 32 | Write-EventLog -LogName $LogName -Source $ScriptName -EventID "100" -EntryType "Information" -Message $Message 33 | 34 | Try 35 | { 36 | Import-Module .\includes\ActiveDirectoryManagement.psm1 37 | Import-Module .\includes\DellWebsiteFunctions.psm1 38 | } 39 | Catch 40 | { 41 | Write-Warning "Must have the ActiveDirectoryManagement or DellWebsiteFunctions Modules available." 42 | Write-EventLog -LogName $LogName -Source $ScriptName -EventID "101" -EntryType "Error" -Message "ActiveDirectoryManagement or DellWebsiteFunctions Modules Not Found" 43 | Break 44 | } 45 | 46 | $Computers = Get-ADObjects -ADSPath $ADSPath 47 | } 48 | Process 49 | { 50 | $Jobs = @() 51 | Foreach ($Computer in $computers) 52 | { 53 | If ($computer.properties.name -ne $null) 54 | { 55 | $Jobs += Get-DellBIOSReport -ComputerName $Computer.Properties.name 56 | } 57 | } 58 | } 59 | End 60 | { 61 | $Message = "Script: " + $ScriptPath + "`nScript User: " + $Username + "`nFinished: " + (Get-Date).toString() 62 | Write-EventLog -LogName $LogName -Source $ScriptName -EventID "100" -EntryType "Information" -Message $Message 63 | 64 | Return $Jobs 65 | } 66 | -------------------------------------------------------------------------------- /vbs/playground/file_stat.vbs: -------------------------------------------------------------------------------- 1 | ' file_stat.vbs 2 | ' Determine the largest, smallest, and average file sizes 3 | ' in the subdirectories of a given directory 4 | ' 5 | ' http://gallery.technet.microsoft.com/scriptcenter/8ab05dfd-f476-4e62-9333-203109d225c2 6 | ' ----- configuration ----- 7 | 8 | strFolderPath = "U:\" 9 | 10 | strLogFile = "C:\TEMP\filestats.log" 11 | ' ----------------------------- 12 | Const ForAppending = 8 13 | 14 | ' Open log file for appending 15 | 16 | Set objFSO = CreateObject("Scripting.FileSystemObject") 17 | Set objLogFile = objFSO.OpenTextFile( strLogFile, ForAppending) 18 | 19 | ' Walk the tree, logging info to file 20 | 21 | 'Set objFSO = CreateObject("Scripting.FileSystemObject") 22 | Set objParent = objFSO.GetFolder( strFolderPath ) 23 | 24 | For Each objFolder in objParent.SubFolders 25 | 'Field: FolderName 26 | objLogFile.Write ( objFolder.Path & ",") 27 | 'Field: StartTime 28 | objLogFile.Write ( now() & ",") 29 | 30 | ' Get statistics 31 | iLargest = 0 32 | iCount = 0 33 | iTotal = 0 34 | 35 | ProcessFolders objFolder 36 | 37 | 'Field: FileCount 38 | objLogFile.Write ( iCount & ",") 39 | 40 | If iCount > 0 Then 41 | 'Field: Largest 42 | objLogFile.Write(iLargest & ",") 43 | 'Field: Average 44 | objLogFile.Write((iTotal/iCount) & ",") 45 | Else 46 | 'no values if no files 47 | objLogFile.Write(",,") 48 | 49 | End IF 50 | 'Field: Finished 51 | objLogFile.Write ( now() & VbCrLF) 52 | Next 53 | 54 | objLogFile.Close 55 | 56 | '------------------------------------------------------------- 57 | ' Recursive subroutine for processing all files and subfolders 58 | 59 | Sub ProcessFolders( objFolder ) 60 | For Each objSubFolder in objFolder.SubFolders 61 | 'Wscript.Echo objSubFolder.Path 62 | ProcessFolders objSubFolder 63 | Next 64 | 65 | Set colFiles = objFolder.Files 66 | 67 | For Each objFile in colFiles 68 | iCount = iCount + 1 69 | 70 | 'The First File is the largest and Smallest 71 | if iCount = 1 Then 72 | iLargest = ObjFile.Size 73 | End If 74 | 75 | 'is this the largest file? 76 | if objFile.Size > iLargest Then 77 | iLargest = objFile.Size 78 | End If 79 | 80 | iTotal = iTotal + ObjFile.Size 81 | 82 | Next 83 | 84 | End Sub -------------------------------------------------------------------------------- /wiki/GetDomainUsers.wiki: -------------------------------------------------------------------------------- 1 | = !Get-DomainUsers.ps1 = 2 | {{{ 3 | 4 | NAME 5 | C:\mod-posh\powershell\production\Get-DomainUsers.ps1 6 | 7 | SYNOPSIS 8 | Return a list of user accounts from the domain. 9 | 10 | SYNTAX 11 | C:\mod-posh\powershell\production\Get-DomainUsers.ps1 [[-ADSPath] ] [[-SearchFilter] ] [[-ADProperties] ] [] 13 | 14 | 15 | DESCRIPTION 16 | This script uses the Get-ADObjects function to return a list of user objects. The 17 | name, pwdLastSet, userAccountControle, adsPath and lastLogonTimestamp are returned. 18 | 19 | 20 | PARAMETERS 21 | -ADSPath 22 | The LDAP URL of your current domain 23 | 24 | Required? false 25 | Position? 1 26 | Default value 27 | Accept pipeline input? false 28 | Accept wildcard characters? 29 | 30 | -SearchFilter 31 | What to filter your query on 32 | 33 | Required? false 34 | Position? 2 35 | Default value 36 | Accept pipeline input? false 37 | Accept wildcard characters? 38 | 39 | -ADProperties 40 | A list of properties to return from AD 41 | 42 | Required? false 43 | Position? 3 44 | Default value 45 | Accept pipeline input? false 46 | Accept wildcard characters? 47 | 48 | 49 | This cmdlet supports the common parameters: Verbose, Debug, 50 | ErrorAction, ErrorVariable, WarningAction, WarningVariable, 51 | OutBuffer and OutVariable. For more information, type, 52 | "get-help about_commonparameters". 53 | 54 | INPUTS 55 | 56 | OUTPUTS 57 | 58 | NOTES 59 | 60 | 61 | ScriptName: Get-DomainUsers 62 | Created By: Jeff Patton 63 | Date Coded: 06/17/2011 64 | ScriptName is used to register events for this script 65 | LogName is used to determine which classic log to write to 66 | 67 | -------------------------- EXAMPLE 1 -------------------------- 68 | 69 | C:\PS>Get-DomainUsers |Export-Csv -Path ./DomainUsers.csv -NoTypeInformation 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | RELATED LINKS 80 | https://code.google.com/p/mod-posh/wiki/Get-DomainUsers 81 | 82 | 83 | 84 | }}} 85 | -------------------------------------------------------------------------------- /powershell/playground/Sccm-Logs.ps1: -------------------------------------------------------------------------------- 1 | function Write-Log 2 | { 3 | <# 4 | .Synopsis 5 | Write a message to a log file in a format compatible with Trace32 and Config Manager logs. 6 | .Description 7 | This cmdlet takes a given message and formats that message such that it's compatible with 8 | the Trace32 log viewer tool used for reading/parsing System Center log files. 9 | 10 | The date and time (to the millisecond) is determined at the time that this cmdlet is called. 11 | Several optional arguments can be provided, to define the Component generating the log 12 | message, the File that is generating the message, the Thread ID, and the Context under which 13 | the log entry is being made. 14 | .Parameter Message 15 | The actual message to be logged. 16 | .Parameter Component 17 | The Component generating the logging event. 18 | .Parameter File 19 | The File generating the logging event. 20 | .Parameter Thread 21 | The Thread ID of the thread generating the logging event. 22 | .Parameter Context 23 | .Parameter FilePath 24 | The path to the log file to be generated/written to. By default this cmdlet looks for a 25 | variable called "WRITELOGFILEPATH" and uses whatever path is there. This variable can be 26 | set in the script prior to calling this cmdlet. Alternatively a path to a file may be 27 | provided. 28 | .Parameter Type 29 | The type of event being logged. Valid values are 1, 2 and 3. Each number corresponds to a 30 | message type: 31 | 1 - Normal messsage (default) 32 | 2 - Warning message 33 | 3 - Error message 34 | #> 35 | [CmdletBinding()] 36 | param( 37 | [Parameter( Mandatory = $true )] 38 | [string] $Message, 39 | [string] $Component="", 40 | [string] $File="", 41 | [string] $Thread="", 42 | [string] $Context="", 43 | [string] $FilePath=$WRITELOGFILEPATH, 44 | [ValidateSet(1,2,3)] 45 | [int] $Type=1 46 | ) 47 | 48 | begin 49 | { 50 | $TZBias = (Get-WmiObject -Query "Select Bias from Win32_TimeZone").bias 51 | } 52 | 53 | process 54 | { 55 | $Time = Get-Date -Format "HH:mm:ss.fff" 56 | $Date = Get-Date -Format "MM-dd-yyyy" 57 | 58 | $Output = "" 61 | 62 | Write-Verbose "$Time $Date`t$Message" 63 | Out-File -InputObject $Output -Append -NoClobber -Encoding Default -FilePath $FilePath 64 | } 65 | } -------------------------------------------------------------------------------- /vbs/production/mfd.vbs: -------------------------------------------------------------------------------- 1 | ' 2 | ' Map MFD Printers for XP 3 | ' 4 | ' August 17, 2010 - Jeffrey S. Patton 5 | ' jspatton@ku.edu 6 | ' 7 | ' Original Source 8 | ' http://code.patton-tech.com/release/production/mfd.vbs 9 | ' 10 | ' Bug Report 11 | ' http://projects.patton-tech.com/scripts/newticket 12 | ' 13 | ' This script maps the new mfd printers for the School of Engineering. 14 | ' 15 | ' USAGE: 16 | ' Place this script on a network share that all users are able to access 17 | ' preferrably a read-only share, otherwise you will want to deny write 18 | ' to this script. 19 | ' 20 | ' Call this script as a logon script, and the only parameter that 21 | ' needs to be specified is the printer share name. 22 | ' 23 | ' Two options can be set within the script bolDefault and strPrintServer. 24 | ' 25 | ' bolDefault is either vbTrue or vbFalse, and determines wether or not the 26 | ' provided pritner will be set as the default printer. 27 | ' 28 | ' strPrintServer is the FQDN of the server hosting the shared printer. 29 | ' 30 | ' GPO Requirements: 31 | ' The GPO that calls this script needs to have the following policy 32 | ' set to disabled. 33 | ' 34 | ' User Configuration\Policies\Administrative Templates\Printers\Point and Print Restrictions 35 | ' 36 | ' Disabling this policy allows users to install printers from 37 | ' servers that are not in the same domain as the computer where the 38 | ' printer is being installed from. 39 | ' 40 | Option Explicit 41 | Dim bolDefault 42 | Dim strPrintServer 43 | 44 | bolDefault = vbTrue 45 | strPrintServer = "printserver.company.com" 46 | 47 | Call ConnectPrinters(LCase(strPrintServer), LCase(Wscript.Arguments.Item(0)), bolDefault) 48 | 49 | Sub ConnectPrinters(strPrintServer, strPrinter, bolDefault) 50 | Dim objNetwork 51 | 52 | On Error Resume Next 53 | Set objNetwork = CreateObject("Wscript.Network") 54 | 55 | objNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & strPrinter 56 | If Err <> 0 Then 57 | Call LogData(1, "Error Number: " & Err.Number & vbCrLf & "Error Description: " & err.Description) 58 | Err.Clear 59 | End If 60 | 61 | If bolDefault = vbTrue Then 62 | objNetwork.SetDefaultPrinter "\\" & strPrintServer & "\" & strPrinter 63 | End If 64 | End Sub 65 | 66 | Sub LogData(intCode, strMessage) 67 | ' Write data to application log 68 | ' 69 | ' http://www.microsoft.com/technet/scriptcenter/guide/default.mspx?mfr=true 70 | ' 71 | ' Event Codes 72 | ' 0 = Success 73 | ' 1 = Error 74 | ' 2 = Warning 75 | ' 4 = Information 76 | Dim objShell 77 | 78 | Set objShell = Wscript.CreateObject("Wscript.Shell") 79 | 80 | objShell.LogEvent intCode, strMessage 81 | 82 | End Sub 83 | -------------------------------------------------------------------------------- /wiki/UpdateVmFromTemplate.wiki: -------------------------------------------------------------------------------- 1 | = !Update-VmFromTemplate.ps1 = 2 | {{{ 3 | 4 | NAME 5 | C:\mod-posh\powershell\production\Update-VmFromTemplate.ps1 6 | 7 | SYNOPSIS 8 | Create a new VM from an imported template 9 | 10 | SYNTAX 11 | C:\mod-posh\powershell\production\Update-VmFromTemplate.ps1 [-TargetVM] [-NewVMName] < 12 | String> [] 13 | 14 | 15 | DESCRIPTION 16 | This script will modify a VM on Hyper-V R2 that has been imported from an exported VM. 17 | The current release of the HyperV module does not support the proper Import method, so 18 | I don't implement that bit in this script. 19 | 20 | 21 | PARAMETERS 22 | -TargetVM 23 | This is the name of the imported VM Template 24 | 25 | Required? true 26 | Position? 1 27 | Default value 28 | Accept pipeline input? false 29 | Accept wildcard characters? 30 | 31 | -NewVMName 32 | This is the name you wish to give your new VM 33 | 34 | Required? true 35 | Position? 2 36 | Default value 37 | Accept pipeline input? false 38 | Accept wildcard characters? 39 | 40 | 41 | This cmdlet supports the common parameters: Verbose, Debug, 42 | ErrorAction, ErrorVariable, WarningAction, WarningVariable, 43 | OutBuffer and OutVariable. For more information, type, 44 | "get-help about_commonparameters". 45 | 46 | INPUTS 47 | 48 | OUTPUTS 49 | 50 | NOTES 51 | 52 | 53 | ScriptName: Update-VmFromTemplate.ps1 54 | Created By: Jeff Patton 55 | Date Coded: August 3, 2011 56 | ScriptName is used to register events for this script 57 | LogName is used to determine which classic log to write to 58 | 59 | You will need the HyperV Module from Codeplex 60 | http://pshyperv.codeplex.com/ 61 | 62 | -------------------------- EXAMPLE 1 -------------------------- 63 | 64 | C:\PS>.\Update-VmFromTemplate.ps1 -TargetVM "2008 Core Server" -NewVMName "IIS Web Server" 65 | 66 | 67 | Description 68 | ----------- 69 | This is the only syntax for this script. 70 | 71 | 72 | 73 | 74 | 75 | 76 | RELATED LINKS 77 | https://code.google.com/p/mod-posh/wiki/Update-VmFromTemplate 78 | http://technet.microsoft.com/en-us/magazine/ff458346.aspx 79 | http://pshyperv.codeplex.com/ 80 | 81 | 82 | 83 | }}} 84 | --------------------------------------------------------------------------------