Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all 15028 articles
Browse latest View live

I know nothing about scripting, but need help with Powershell on a Mac

$
0
0

I'm trying to customise my Microsoft email Encryption emails by replacing the Microsoft logo with my own. I'm basically just following instructions here: https://docs.microsoft.com/en-us/office365/securitycompliance/add-your-organization-brand-to-encrypted-messages.

Could someone help me understand how I adapt this for MacOs, specially the file location part?

Set-OMEConfiguration -Identity "Branding Template 1" -Image (Get-Content "C:\Temp\contosologo.png" -Encoding byte)

When I enter (Get-Content"/User/Desktop/filename.png" -Encoding byte)I get an error message. My questions is: How do I point to a file on my desktop on the Mac?

Thanks for any help. I'm lost.



Script to check if multiple files exist powershell - not working

$
0
0
$ServerName = Get-Content "c:\dev\Computers.txt" 

$path = 'C$\Program Files (x86)\Microsoft Office\root\Office16\winword.exe'
$path = 'C$\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE'
$path = 'C$\Program Files (x86)\Microsoft Office\root\Office16\POWERPNT.EXE'
$path = 'C$\Program Files (x86)\Microsoft Office\root\Office16\OUTLOOK.EXE' 
  
foreach ($Server in $ServerName) {  
  
        if (test-Connection -ComputerName $Server -Count 2 -Quiet ) {   
          
            $computers | % { 
            '{0}: {1}' -f $_, (Test-Path -LiteralPath "\\$_\$path") }
          
                    } else  
                      
                    {"$Server not pinging"  
              
                    }      
          
                                } 

How to eject USB Attached SCSI (UAS) Compatible Device?

$
0
0

I cannot find an example of PowerShell being used to eject a USB attached SCSI (UAS) compatible device(device type 3).  There must be a way to do this because the device can be ejected using "Safely remove hardware and eject media" tool.  I can eject regular USB thumb drives (device type 2) with PowerShell with out issue.

Powershell script to remove unwanted file extension

$
0
0

Thanks to a Backup program that will remain nameless(although when you see the extension, you will know who it is) I have 1000's of files on an external disk that have a .IAB attached to the end of a file (ie: reporting.xls.iab for example). These files are scattered throughout the disk in about 250 directories and subdir as well. I've found that if I rename the file by deleting the extra extension the file is in tact and useable. Mainly any file with .exe, .doc, .xls, .ppt are the ones I'm most interested in but I would be happy to have all the files be renamed without the .IAB.

Is there a script out there that can handle this? I know you Scripting Guys can work magic and I'm hoping you can do your thing here as well.

 

Thanks Pogo7720

Rename a file in VBSCRIPT

$
0
0
How do I rename a file if all I know is that it will be the only .txt file in the directiory? Using VBSCRIPT

How to use variable array in If-Else statement

$
0
0

How can I clean up the below / get it to work?  Goals are listed within comment blocks.  Thank you for the help.

$Julian = (Get-Date).DayOfYear
$Path = "C:\Users\Public\Desktop\"
<# Ultimate Goal (so that I don't have to add/update variable
Returns files as objects; but haven't figured out how to use
"Foreach-Object" yet #>
$uFiles = (get-ChildItem -Path$Path *.$Julian)
<# Interm Goal - Use variable array to act as the input and
only run the "if" statement one time (if possible) #>
$iFiles = "File1","File2", "File3"
<# Current process #>
$cFiles = "File1"
if ((Get-ChildItem -Path$Path -Filter $cFiles*.$Julian |
get-content | Measure-Object -line).Lines -gt 1)
{write-host Use $cFiles} else {write-hostDo NOT Use $cFiles}
$cFiles = "File2"
if ((Get-ChildItem -Path$Path -Filter $cFiles*.$Julian |
get-content | Measure-Object -line).Lines -gt 1)
{write-host Use $cFiles} else {write-hostDo NOT Use $cFiles}
$cFiles = "File3"
if ((Get-ChildItem -Path$Path -Filter $cFiles*.$Julian |
get-content | Measure-Object -line).Lines -gt 1)
{write-host Use $cFiles} else {write-hostDo NOT Use $cFiles}

How we can generate certificate for remote computers using "New-SelfsignedCertificateEx"

try catch block will not capture errors

$
0
0

Hi guys,

Im unsure why this is not capturing the errors and writing an error to the screen.

It is also not appending them to an error file.

I am trying to check whether a user in the file is licensed and find what licences they have assigned.

can someone please assist?

This script is being executed using Powershell v2.0

import file has a header of :  userprincipalname

code:

$users = Import-Csv c:\Temp\Check_ems_licence_user.csv

foreach ($user in $users)  {

try {

Get-MsolUser -userprincipalname $user.userprincipalname | select displayname, userprincipalname, islicensed, licenses | ft -auto
}

Catch  [Microsoft.Online.Administration.Automation.MicrosoftOnlineException]
{
Write-Host "$User does NOT exist!"
}
Catch {
$_ | Out-File C:\Temp\Ems_errors.txt -Append
}
}


Thanks for your assistance.



Write Event Log

$
0
0

Hey All,

I would like some help to write a script that i run to get Windows Update URL's and Managed to put into the Event Log 

This is my Current Script.

$MUSM = New-Object -ComObject "Microsoft.Update.ServiceManager"
$MUSM.Services | select Name, ServiceUrl,IsManaged



Which results in this 

NameServiceUrlIsManaged
DCat Flighting Prodhttps://fe3.delivery.mp.microsoft.com/FALSE
Windows Store (DCat Prod)https://fe3.delivery.mp.microsoft.com/FALSE
Windows Updatehttps://fe2.update.microsoft.com/v6/FALSE

Now i would like if the IsManaged us True to write to the event log and the Windows update ServiceURL is not https://fe2.update.microsoft.com/v6/ to write to the event log 

I'm Very new to Powershell so any help would be great.

Adding Multiple users to Multiple AD Groups

$
0
0

I have a .csv file with 2 columns. Sam and Newgroup

Column 1 -Sam is the SAM account name in AD for the user I am trying to add into the groups.

Column 2 -Groups column has multiple groups in a single cell separated by ; Like this. test1;test2;test3

Code I am working with is this

$Users=import-csv-Path"C:\filename.csv" -delimiter';'


foreach ($User in $Users) {

$SAM = $user.Sam

$Group = $User.newgroup
Add-ADGroupMember - Identity $Group -Members $SAM

}

Error is as follows

Add-ADGroupMember : Cannot validate argument on parameter 'Identity'. The argument is null.

New to powershell so a little lost


}

Powershell script to delete specific folders by scanning through folder hierarchy and delete specific folders.

$
0
0

Hi,

I have around 200 GB data which is needed to clean

 which contains some files and folders, the folder hierarchy is same and their are two levels and some have 3 levels of hierarchy.

I am looking for powershell code that will scan through folder structure and remove some specific folders from Data.

Powershell keeps running commands in new terminals.

$
0
0

Two things before I go into the issue

  1. I am waaay more comfy in Bash then Powershell \ CMD
  2. Sorry if this is the wrong area of the forum, but couldn't find anywhere else that this would fit.

Anyway, I keep getting this issue where if I run certain commands, instead of running it in the terminal I'm working in, it'll spawn a new session, run the command, then terminate that session... Taking any output along with it. 

Right now, I'm going through a kubernetes \ docker tutorial for example. Running the following commands

kubectl version
docker version
minukube version

I see another window briefly open, which I initially thought was CMD, due to it's looks, before I see a flash of the output and then the window closes. Running commands that take time will result in the window opening and tailing said command, then once it errors or finish's, it closes, taking its output with it.

How do I stop this behaviour? The guides I am following show this commands running natively inside the expected terminal, not a new one.


Alistair Hardy

Powershell 5.1 - XML Parse Error after Text Replacement

$
0
0

Hello,

The following code appears to run perfectly. It is run on a single domain controller as part of renaming the forest. Yes. I want to do this. 

The text in the XML file is replaced properly, but when I run rendom /showforest, I get the following error message:
Failed to parse the file Domainlist.xml: Win32 Error -1072896682 :-1072896682

$OldDNSName="ad.publicdns.tld"
$NewDNSName="dc.waynecharities.org"
$OldNetBIOSName="AD"
$NewNetBIOSName="DC"

rendom /list

$Domainlist = Get-Content .\Domainlist.xml
$Domainlist | % { $_.Replace($OldDNSName,$NewDNSName) } | Set-Content .\Domainlist.xml
$Domainlist = Get-Content .\Domainlist.xml
$Domainlist | % { $_.Replace("<NetBiosName>$OldNetBIOSName</NetBiosName>","<NetBiosName>$NewNetBIOSName</NetBiosName>") } | Set-Content .\Domainlist.xml

rendom /showforest

The above should be readily duplicatable and will not actually push any changes. Of course, the obvious thought is that there is some change within the file syntax (an extra space, spelling issue, etc.). However, I have been over the side-by-side comparison and cannot find it. So I am hoping:

1. Someone out there has better eyes than me and will enjoy the opportunity for some basic correction, or

2. Someone knows a mechanical, underlying reason this is not working and will maybe even provide me the Select-Xml version since I am not winning with my text replacement.

Funny side note:

The file is still named Domainlist.xml, but the file size actually goes down from showing 2kb in File Explorer to 1kb after the script is run. this makes me think it is something under-the-hood:

Thank you much in advance! I've been hammering away at this for longer than I care to admit :)


Script/Powershell to rename files names

$
0
0

Hey guys,

I a bit new to powershell and was wondering if you guys can assist me here? Excuse my poor english since it's not my first language. Anyhow, I have files name something like p2122938.ext, p2724942.ext, etc.. Over a thousand of them and wanted to rename them to different things such as p2122938.ext would rename to iloveyou and p272494.ext would be rename to ihateyou. I have seperated these .ext name into a text and the renamed such as iloveyou, ihateyou into another text file. Basically, I was wondering how to write a script to pull those two text file and rename the actual file in a certain folder. Example, .ext file names is in test1.txt and the rename I want them to be is in a text file test2.txt, run script and it would replace all the actual file in MyDocument\p*.ext to test2.txt naming base off test1.txt. 

Thanks,

Sl0th

Rowset Cannot be loaded because the stream is invalid

$
0
0

We are getting error :Rowset Cannot be loaded because the stream is invalid for  few of the users which try and access the system

We have recently migrated from window 2003 to windows 2012

We are using ADODB.Recordset


Powershell Script to Automate sending a text message -- Google Voice

$
0
0
Need to complete this script to text my phone and let me know my computer is connected to the VPN. Anyone able to see any coding problems?

#Variables $username_or_email = "USERNAME"; $password = "PASSWORD"; $url = "https://accounts.google.com/ServiceLogin?service=grandcentral&passive=1209600&continue=https://www.google.com/voice&followup=https://www.google.com/voice&ltmpl=open"; $phone = "YOURNUMBER" $send = $sending | where {$_.innerText -eq 'Send'} $text = $texts | where {$_.innerText -eq 'Text'} $ProcessActive = Get-Process dsNetworkConnect -ErrorAction SilentlyContinue if($ProcessActive -eq $null) { # Create an ie com object $ie = New-Object -com internetexplorer.application; $ie.visible = $true; $ie.navigate($url); # Wait for the page to load while ($ie.Busy -eq $true) { Start-Sleep -Milliseconds 3000; } # Add login details $ie.Document.getElementById("Email").value = $username_or_email; $ie.Document.getElementById("Passwd").value = $password; while ($ie.Busy -eq $true) { Start-Sleep -Milliseconds 5000; } # Click the button to login. $ie.Document.getElementById("signIn").Click(); # Wait for the page to load while ($ie.Busy -eq $true) { Start-Sleep -Milliseconds 5000; } # Hidden click text button -- no visual that it clicked it if you watching this run $ie.Document.getElementById("$text").Click(); # Insert phone number, message, and send it. $ie.Document.getElementById("gc-quicksms-number").value = "$phone" $ie.Document.getElementById('gc-quicksms-text2').SetAttribute('value','Connected') $ie.Document.getElementById("$send").Click(); } else { # Create an ie com object $ie = New-Object -com internetexplorer.application; $ie.visible = $true; $ie.navigate($url); # Wait for the page to load while ($ie.Busy -eq $true) { Start-Sleep -Milliseconds 3000; } # Add login details $ie.Document.getElementById("Email").value = $username_or_email; $ie.Document.getElementById("Passwd").value = $password; while ($ie.Busy -eq $true) { Start-Sleep -Milliseconds 5000; } # Click the button to login. $ie.Document.getElementById("signIn").Click(); # Wait for the page to load while ($ie.Busy -eq $true) { Start-Sleep -Milliseconds 5000; } # Hidden click text button -- no visual that it clicked it if you watching this run $ie.Document.getElementById("$text").Click(); # Insert phone number, message, and send it. $ie.Document.getElementById("gc-quicksms-number").value = "$phone" $ie.Document.getElementById('gc-quicksms-text2').SetAttribute('value','Not Connected') $ie.Document.getElementById("$send").Click(); }



Powershell Check number of words in Line

$
0
0

i have variable $name

it contains John Doe string

I want to check if line contains 2 or more that 2 words

If it contains 2 words (John Doe) create new variable which will consist from first word of First name and append Last name

(JDoe), if $body variable contains more than 2 words (John JR Doe) create this variable: JJRDoe (append First Name Character) with other Words

I manged only to extract first word

$fname = $name.split(" ")[0]

$lname = $name.split(" ")[1]

so i cat get John and can get last name

But no idea how to check if there are 2 or three words


multiple values in read host

$
0
0

Hi 

I am using following code to filter specific folders using read host  command. How can I put multiple folder in read-host input as I have multiple folder names to filter? Thanks


#This is what Directory you want to search
$searchDir = Read-Host "C:\Users\admin\Desktop\dir2dir"

#This is what folder, you're searching for
$searchFolder = Read-Host "folderA, folderB, folderC"

#This is the location of your logfile of results if you choose to
#have the results written to the logfile (uncomment the line below)
$outputDir = "C:\scripts\files_$(get-date -f yyyy-MM-dd).csv"
$files = Get-ChildItem -Path $searchDir -Recurse -Filter $searchFile -EA silentlyContinue | Select Fullname, @{Name="MegaBytes"; Expression={"{0:F2}" -f ($_.Length / 1MB)}}, CreationTime, LastAccessTime | Sort-Object MegaBytes -Descending

#The results output to a CSV file
$files | Export-Csv $outputDir

write-host -foregroundcolor yellow "Search complete, results can be viewed here: $outputDir"

#Start excel and open the logfile of the results
Start-Process Excel -ArgumentList $outputDir

Script to list directory changes.

$
0
0

The script is to scan a directory tree and compare it to a previous scan and determine list files that have been changed or deleted or added.  I am having with the compare-object function.  If I change a file, it doesn't show it.  If I delete a file it just returns the last file.

PLease help.

Here is the script:

$PreviousScanFile = "d:\temp\filespreviousscan.csv"
$ChangeRecordFile = "d:\temp\ChangeRecordFile.csv"

$PreviousScan = import-csv -Path $PreviousScanFile

$files = Get-ChildItem -Path "\\sti\filecab\it software" -Recurse -Force | Where-Object { !$_.PSIsContainer } | select -property name,lastwritetime,CreationTime,FullName 
 
"Finding changed files"

$changedFiles = compare-object -ReferenceObject $files -DifferenceObject $PreviousScan -PassThru

$files | export-csv -Path $PreviousScanFile 

$changedFiles
$changedfiles.count
$files.count
$PreviousScan.count

Copying computer account descriptions from one domain to another

$
0
0

I have two AD domains, one of which has all the computer accounts disabled that we are no longer user, the other where all the computers currently reside with the same names.  They're spread out between differently named OUs in both domains.   The computers in the old domain have all the Description fields filled out, the computer accounts in the new domain do not. Can anyone point me in the right direction on what would be best to copy the description from the old domain's computer accounts into the same-named computers in the new domain?   seems like it would be safer to limit it to certain OUs somehow right?

Viewing all 15028 articles
Browse latest View live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>