Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions MappedDriveReport.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ param
)

function Get-CurrentDate {
<#
<#
.SYNOPSIS
Get the current date and return formatted value

Expand All @@ -76,7 +76,7 @@ function Get-CurrentDate {
}

function Get-MappedDrives {
<#
<#
.SYNOPSIS
Get list of Mapped Drives

Expand Down Expand Up @@ -112,8 +112,8 @@ function Get-MappedDrives {
#Get list of mapped drives
[array]$MappedDrives = (Get-ChildItem REGISTRY::$MappedDrives | Select-Object name).name
foreach ($MappedDrive in $MappedDrives) {
$DriveLetter = (Get-ItemProperty -Path REGISTRY::$MappedDrive | select PSChildName).PSChildName
$DrivePath = (Get-ItemProperty -Path REGISTRY::$MappedDrive | select RemotePath).RemotePath
$DriveLetter = (Get-ItemProperty -Path REGISTRY::$MappedDrive | Select-Object PSChildName).PSChildName
$DrivePath = (Get-ItemProperty -Path REGISTRY::$MappedDrive | Select-Object RemotePath).RemotePath
If ($DrivePath -notin $UNCExclusions) {
$Drives = New-Object System.Management.Automation.PSObject
$Drives | Add-Member -MemberType NoteProperty -Name ComputerName -Value $env:COMPUTERNAME
Expand All @@ -128,7 +128,7 @@ function Get-MappedDrives {
}

function Get-RelativePath {
<#
<#
.SYNOPSIS
Get the relative path

Expand All @@ -147,7 +147,7 @@ function Get-RelativePath {
}

function Invoke-SCCMHardwareInventory {
<#
<#
.SYNOPSIS
Initiate a Hardware Inventory

Expand Down Expand Up @@ -178,13 +178,14 @@ function New-WMIClass {
)

$WMITest = Get-WmiObject $Class -ErrorAction SilentlyContinue
If ($WMITest -ne $null) {
If ($null -ne $WMITest) {
$Output = "Deleting " + $WMITest.__CLASS[0] + " WMI class....."
Remove-WmiObject $Class
$WMITest = Get-WmiObject $Class -ErrorAction SilentlyContinue
If ($WMITest -eq $null) {
If ($null -eq $WMITest) {
$Output += "success"
} else {
}
else {
$Output += "Failed"
Exit 1
}
Expand All @@ -198,27 +199,28 @@ function New-WMIClass {
$newClass.Properties["ComputerName"].Qualifiers.Add("key", $true)
$newClass.Properties["ComputerName"].Qualifiers.Add("read", $true)
$newClass.Properties.Add("DriveLetter", [System.Management.CimType]::String, $false)
$newClass.Properties["DriveLetter"].Qualifiers.Add("key", $false)
$newClass.Properties["DriveLetter"].Qualifiers.Add("key", $true)
$newClass.Properties["DriveLetter"].Qualifiers.Add("read", $true)
$newClass.Properties.Add("DrivePath", [System.Management.CimType]::String, $false)
$newClass.Properties["DrivePath"].Qualifiers.Add("key", $false)
$newClass.Properties["DrivePath"].Qualifiers.Add("read", $true)
$newClass.Properties.Add("Username", [System.Management.CimType]::String, $false)
$newClass.Properties["Username"].Qualifiers.Add("key", $false)
$newClass.Properties["Username"].Qualifiers.Add("key", $true)
$newClass.Properties["Username"].Qualifiers.Add("read", $true)
$newClass.Put() | Out-Null
$WMITest = Get-WmiObject $Class -ErrorAction SilentlyContinue
If ($WMITest -eq $null) {
If ($null -eq $WMITest) {
$Output += "success"
} else {
}
else {
$Output += "Failed"
Exit 1
}
Write-Output $Output
}

function New-WMIInstance {
<#
<#
.SYNOPSIS
Write new instance

Expand Down Expand Up @@ -253,7 +255,7 @@ function New-WMIInstance {
}

function Start-ConfigurationManagerClientScan {
<#
<#
.SYNOPSIS
Initiate Configuration Manager Client Scan

Expand All @@ -279,7 +281,7 @@ function Start-ConfigurationManagerClientScan {
[Void]$SMSwmi.TriggerSchedule($Action)
}

cls
Clear-Host
#Get list of mapped drives for each user
$UserMappedDrives = Get-MappedDrives
#Write output to a text file if -OutputFile is specified
Expand All @@ -291,23 +293,24 @@ If ($OutputFile.IsPresent) {
}
#Write list of mapped drives to the specified text file.
[string]$OutputFile = [string]$TextFileLocation + $env:COMPUTERNAME + ".txt"
} else {
}
else {
#Get the relative path this script was executed from
$RelativePath = Get-RelativePath
$OutputFile = $RelativePath + $env:COMPUTERNAME + ".txt"
}
If ((Test-Path $OutputFile) -eq $true) {
Remove-Item $OutputFile -Force
}
If (($UserMappedDrives -ne $null) -and ($UserMappedDrives -ne "")) {
If (($null -ne $UserMappedDrives) -and ($UserMappedDrives -ne "")) {
$UserMappedDrives | Format-Table -AutoSize | Out-File $OutputFile -Width 255
}
}
If ($SCCMReporting.IsPresent) {
#Create the new WMI class to write the output data to
New-WMIClass -Class "Mapped_Drives"
#Write the output data as an instance to the WMI class
If ($UserMappedDrives -ne $null) {
If ($null -ne $UserMappedDrives) {
New-WMIInstance -MappedDrives $UserMappedDrives -Class "Mapped_Drives"
}
#Invoke a hardware inventory to send the data to SCCM
Expand Down