7/25/2017 - 5:07 PM

network share navigation pushd

network share navigation

# command to run script on multiple machines in domain
Invoke-Command -ComputerName PC1,PC2,PC3 -FilePath C:\myFolder\myScript.ps1
enter-pssession -ComputerName target

invoke-command -ScriptBlock {$PSVersionTable} -ComputerName target
.\PsExec \\WS898 -s powershell Enable-PSRemoting -Force
# Logger function usage
# Create a folder in this directory \\sccm\sccm$\UpgradeLog
# call the function like this
# logger "string to log"

function logger{

    # define these values
    $path_to_log_folder = "\\sccm\sccm$\UpgradeLog"
    $name_of_folder = "TesterLog"

    $Username = (Get-WmiObject -Class Win32_ComputerSystem | select username).Username.Substring(5)
    $Username = (Get-Culture).TextInfo.ToTitleCase($Username)

    function Time {
        $d = Get-Date
        [string]$dw = $d.DayOfWeek
        $dw = $dw.Substring(0,3)
        $dw + " " + $d

    Add-Content $path_to_log_folder\$name_of_folder\$CPName-$Username.txt "$(time) $CPName $Username $arg0"


logger "test call this wherever you need test 1"
logger "test call this wherever you need test 2"
logger "test call this wherever you need test 3"
logger "test call this wherever you need test 4"
logger "test call this wherever you need test 5"
logger "test call this wherever you need test 6"
logger "test call this wherever you need test 7"
logger "test Close out log test 8"
logger "---------------------------------------"

# include any processes that you would like to check for 
# this is an Object in Powershell
$processBundle = @{
    "Revit" = "revit";
    "Acad" = "acad";
    "NavMan" = "roamer";

function processCheck{
    # when using an object it has it own type
    $p1 = get-process -name $arg1.Revit -ea 0
    $p2 = get-process -name $arg1.Acad -ea 0
    $p3 = get-process -name $arg1.NavMan -ea 0
    $p4 = get-process -name 'acad' -ea 0

processCheck $processBundle
# check the type of the variable
# this might iterate over the objects properties
# function
# usage .\Get-Programs.ps1 WS912 -outputfile ".\reports\softwareWS912.csv"

    Name: Get-Programs.ps1 
    Author: Simon Sheppard, based on a script by Sitaram Pamarthi.
    Requires: PowerShell v2 or higher. 
    1.01   23-June-2015 - Initial Release, with export to CSV.
    List installed Programs on one or more computers.
    This script retrieves the installed software directly from the registry
    it does not rely on having an SCCM client installed.
.PARAMETER ComputerName
    The computer(s) to be checked, by default the local computer.
    Get-Programs.ps1 workstation64

    [string[]]$ComputerName = $env:computername,
    [string]$OutputFile = "C:\batch\Installed_Programs.csv"

    Remove-Item $OutputFile -ErrorAction SilentlyContinue

    function Get-InstalledApps
    # This function will loop through the applications installed on one PC
    # and output one object for each Application with all its properties.
    # optionally saving/appending to a .CSV spreadsheet.
        foreach ($App in $Applications)
            $AppRegistryKey = $UninstallRegKey + "\\" + $App
            $AppDetails = $HKLM.OpenSubKey($AppRegistryKey)
            $AppGUID = $App
            $AppDisplayName = $($AppDetails.GetValue("DisplayName"))
            $AppVersion = $($AppDetails.GetValue("DisplayVersion"))
            $AppPublisher = $($AppDetails.GetValue("Publisher"))
            $AppInstalledDate = $($AppDetails.GetValue("InstallDate"))
            $AppUninstall = $($AppDetails.GetValue("UninstallString"))
            if(!$AppDisplayName) { continue }
            $OutputObj = New-Object -TypeName PSobject
            $OutputObj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $Computer.ToUpper()
            $OutputObj | Add-Member -MemberType NoteProperty -Name AppName -Value $AppDisplayName
            $OutputObj | Add-Member -MemberType NoteProperty -Name AppVersion -Value $AppVersion
            $OutputObj | Add-Member -MemberType NoteProperty -Name AppVendor -Value $AppPublisher
            $OutputObj | Add-Member -MemberType NoteProperty -Name InstalledDate -Value $AppInstalledDate
            $OutputObj | Add-Member -MemberType NoteProperty -Name UninstallKey -Value $AppUninstall
            $OutputObj | Add-Member -MemberType NoteProperty -Name AppGUID -Value $AppGUID
            if ($RegistryView -eq 'Registry32')
                $OutputObj | Add-Member -MemberType NoteProperty -Name Arch -Value '32'
            } else {
                $OutputObj | Add-Member -MemberType NoteProperty -Name Arch -Value '64'

            # Export to a file
            $OutputObj | export-csv -append -noTypeinformation -path $OutputFile
    foreach($Computer in $ComputerName)
        Write-Output "Computer: $Computer" 
        if(Test-Connection -ComputerName $Computer -Count 1 -ea 0)
            # Get the architecture 32/64 bit
            if ((Get-WmiObject -Class Win32_OperatingSystem -ComputerName $Computer -ea 0).OSArchitecture -eq '64-bit')
                # If 64 bit check both 32 and 64 bit locations in the registry
                $RegistryViews = @('Registry32','Registry64')
            } else {
                # Otherwise only 32 bit
                $RegistryViews = @('Registry32')

            foreach ( $RegistryView in $RegistryViews )
                # Get the reg key(s) where add/remove program information is stored.
                $HKLM = [microsoft.win32.registrykey]::OpenRemoteBaseKey('LocalMachine',$computer,$RegistryView)
                $UninstallRef = $HKLM.OpenSubKey($UninstallRegKey)
                $Applications = $UninstallRef.GetSubKeyNames()

                # Now we have the registry locations, call the function which will enumerate
                # all the applications on this PC

end {}
# this is the traditional 
# not the cool built in iterator way

for ($i=0; $i -le $pathCheck.length; $i++){
    # $path =  $pathCheck[$i]
    # Test-Path $path
    write-host $pathCheck[$i]
connect to network share without mounting drive letter
pushd \\share\share$

pushd detatch
$UseWUServer = Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" -Name "UseWUServer" | Select-Object -ExpandProperty UseWUServer
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" -Name "UseWUServer" -Value 0
Restart-Service "Windows Update"
Get-WindowsCapability -Name "RSAT*" -Online | Add-WindowsCapability –Online
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" -Name "UseWUServer" -Value $UseWUServer
Restart-Service "Windows Update"
# Returns tr
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
get-aduser "username" -server "trelane.rubicorp.com" -properties passwordlastset | ft Name, passwordlastset