I need some help and suggestion on how can I execute this code below from my team desktop while the actual PowerShell modules and the Script.PS1 is located on the \\PAWSVR01-VM\Shared\Script1.PS1 ?
The goal here is to be able to execute the script while the user double-clicking on the script from their desktop will be presented with the login name to remotely executed the server PAWSVR01-VM (Privileged Access Workstation - https://docs.microsoft.com/en-us/securi ... ss-devices).
So all of the Powershell modules are just installed and maintained in the PAWSVR01-VM only rather than on each user's desktop locally.
My script content is like the below:
Code: Select all
Add-Type -AssemblyName 'System.Windows.Forms'
Add-Type -AssemblyName 'System.Drawing'
Add-Type -AssemblyName 'Microsoft.VisualBasic'
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
#######################################################################################################################################################################
$ADURL = 'https://www.microsoft.com/en-us/download/details.aspx?id=45520'
If (-not (Get-Module -ListAvailable ActiveDirectory))
{
Write-Host "No Microsoft Active Directory PowerShell module installed. `n Starting with Windows 10 October 2018 Update, add RSAT tools right from Windows 10. Just go to 'Manage optional features' in Settings and click 'Add a feature' to see the list of available RSAT tools.`n" -WarningAction Continue -ForegroundColor Yellow
return
}
Else
{
Try { Import-Module ActiveDirectory -Force -ErrorAction Stop }
Catch { Write-Warning "Unable to load Microsoft Active Directory PowerShell module because $($Error[0])"; [Diagnostics.Process]::Start($ADURL); return }
}
#######################################################################################################################################################################
$Module = Get-Module -Name Microsoft.Graph -ListAvailable
if ($Module.count -eq 0)
{
Write-Host "Microsoft Graph PowerShell SDK is not available" -ForegroundColor Yellow
$Confirm = Read-Host "Are you sure you want to install module? [Y] Yes [N] No"
if ($Confirm -match "[yY]")
{
Write-host "Installing Microsoft Graph PowerShell module..."
Install-Module Microsoft.Graph -Repository PSGallery -Scope CurrentUser -AllowClobber -Force
}
else
{
Write-Host "Microsoft Graph PowerShell module is required to run this script. Please install module using 'Install-Module Microsoft.Graph' cmdlet."
Exit
}
}
#######################################################################################################################################################################
Write-Host "Connecting to Microsoft Graph..." -ForegroundColor Green
$RequiredScopes = @(
'User.Read.All',
'Group.Read.All',
'UserAuthenticationMethod.Read.All'
)
Connect-MgGraph -Scopes $RequiredScopes
if ((Get-MgContext) -ne "")
{
Write-Host Connected to Microsoft Graph PowerShell using (Get-MgContext).Account account -ForegroundColor Yellow
}