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

Delete network adapters via dos command

$
0
0

I have about one to two hundred PC’s I need to delete 2 network adapters on.

I can’t use PowerShell because some are XP and server 2003 that may not have PowerShell enabled.

It is the Teredo Tunneling Adapter and the Microsoft ISATAP adapter. 

I was sure I could do this in the command line so I could do a batch file to just run on each using netsh but if so I can’t get the syntax.

Can anyone lend any advice on how I can accomplish this with batch?

Thanks


R White


Rename a set of files in Power Shell

$
0
0

Hello Scripting Guys,

I am trying to rename a group of files in a given directory.  The files all start with a number and a dash (such as "1 - " or "24 - ") when I first get them. Sometimes there are files that do not start with a number or a dash in the same directory, but I don't want to bother with those.  Of the files that do have a number and a dash, they should all be .SQL text files (have a .SQL extension).  

I want to loop through all files that meet these criteria and then rename them to the same name, but without the number and the dash.  For example a file may have a name like "1 - cust_sp_Get_Last_Order.sql"  I want to just rename this to "cust_sp_Get_last_order.sql" and be done with it.  

I would be done by now in VBScrpt, but I am trying to learn the bloody PowerShell and it is driving me crazy.

Here is what I came up with, but it chokes on the substring piece.  If I test the substring bit by itself with variables it seems to work fine.  it just does not work in this script.  Please help.


$depfiles = gci c:\Temp -filter *.txt              
$depfiles | %{ [int]$dash_pos = $_.name.indexof("-"); 
               [int]$start = $dash_pos+2;
               [int]$dot = $_.name.indexof(".");
               [int]$end = $dot+3;
               $start; $dot; $end;
               [string]$nameonly = $_.name;
               $new_name = $nameonly.substring($start, $end);
               write "Name:" $nameonly; write "New Name:" $new_name
}


And this is what I get in return....

Exception calling "Substring" with "2" argument(s): "Index and length must refer to a location within 
the string.
Parameter name: length"
At C:\Users\Tom\Desktop\3rd try.ps1:9 char:47
+                $new_name = $nameonly.substring <<<< ($start, $end);
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Thank you.


User Rights Delegation via Powershell (Server 2012)

$
0
0

Hi

In the Exam Ref 70-414 book the author refers the the following powershell cmdlets in server 2012 to assign /delegate user rights by using the constant names.

The cmdlets;

Get-privilege

Grant-privilege

Revoke-privilege

Test-privilege

I am not sure if i'm missing something blatantly, but i seem not to find any information or syntax on this, even after updating powershell help, it doesn't recognize the cmdlets.

Any help will be appreciated.

Querying Office 365 Exchange to create a license usage report.. but getting an IO error intermittently

$
0
0

I have included the powershell function that i am using.  The script returns the data i am looking for.  The issue i am having is the intermittent error:

The I/O operation has been aborted because of either a thread exit or an application request


I found one blog on this here: http://blogs.msdn.com/b/ashour/archive/2014/04/30/large-tenant-and-powershell-i-o-timeout.aspx 

so my question is, does anyone know a way i can cycle through the users in chunks without having to import them from a csv file first?

Function Get-LicenseReport {<#
    .Synopsis
    This Cmdlet generates a report off all Office 365 licensed users
    .Description
    Get-LicenseReport queries Azure AD and generates a CSV report of the users that are licensed and they license SKU assigned to them
    .Example
    Get-LicenseReport -Verbose
    #>
    [CmdletBinding()]
    param()
    $date = Get-Date -Format g
    $msolcred = Get-Credential -Message "Office 365 Username and Password"

    #Clear any current PSSessions
    Get-PSSession | Remove-PSSession

    #Connect to Office 365
    connect-msolservice -credential $msolcred
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $msolcred -Authentication Basic -AllowRedirection
    Import-PSSession $Session -AllowClobber -DisableNameChecking | Out-Null

    #Verify Admindir and create CSV
    $admindir = "$env:HOMEDRIVE\PS_logs"
        If ((Test-Path $admindir) -eq 'false')
        {
        New-Item $admindir -ItemType directory -Force
        }
    $CSV = "$admindir\O365LicenseReport.csv"
    $props = [ordered]@{'UserPrincipalName' = '';'Disabled' = '';'RecipientType' = '';'IsLicensed' = '';'LastLogonDate' = '';'License 1' = '';'License 2' = ''}
    New-Object psobject -Property $props | Export-Csv $CSV -NoTypeInformation -Force
    $users = Get-MsolUser -all | Where {$_.islicensed -eq $true}

    #Loop through each user and write the details to the CSV
    foreach ($user in $users)
    {
        $mbxstats = Get-MailboxStatistics -Identity $user.userprincipalname
        $mbx = Get-Mailbox -Identity $user.UserPrincipalName
       If ($user.licenses.accountskuid.count -gt 1)
        {
        $datastring = ($user.UserPrincipalName + "," + $mbx.accountdisabled + "," + $mbx.recipienttype + "," + $user.IsLicensed + "," + $mbxstats.lastlogontime + "," + $user.Licenses.accountskuid[1] + "," + $user.Licenses.accountskuid[0])
        Out-File $CSV -InputObject $datastring -Encoding UTF8 -append
        }
     Else
        {
        $datastring = ($user.UserPrincipalName + "," + $mbx.accountdisabled +  ","  + $mbx.recipienttype + "," + $user.IsLicensed + "," + $mbxstats.lastlogontime + "," + $user.Licenses.accountskuid)
        Out-File $CSV -InputObject $datastring -Encoding UTF8 -append
        }


    }
    Write-Host "License report has been saved to $CSV"
    Remove-PSSession $Session
}



Create Windows Shortcut With PowerShell - HELP!

$
0
0

Hey, I am trying to create a new shortcut that runs a PowerShell script against the local machine. The problem I am having is that when the Scripts amends the TargetPath it includes the " " (quotation marks) and the shortcut will not run as a result. How can I exclude these? I have tried [regex] escape with no joy. Thanks

Script:

$shell=New-Object -ComObject WScript.Shell
$StartShortcut=$shell.CreateShortcut("C:\Users\$env:username\Desktop\PS_Scripts\Start Services - This Server.lnk")
$StartShortcut.TargetPath = "%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -file D:\powershell\Start-Services.ps1 -computernames $env:computername"
$StartShortcut.IconLocation = "%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe"
$StartShortcut.WorkingDirectory ="%HOMEDRIVE%%HOMEPATH%"
$StartShortcut.TargetLocation = "v1.0"
$StartShortcut.Save()

In need of a Powershell script to move students from an OU to another OU

$
0
0

Good Day Everyone,

I was tasked to move students from the Students OU to Full Time / Part Time OU. I can possibly get this done in a short time BUT since I am a newbie, I would like to know what would be the best approach for me to get this done. 

Details

1. There are about 1700 students

2. Import Students from an CSV file to be moved [fulltimestudents.csv AND parttimestudents.csv]

3. After importing the students > move them to the fulltime or parttime OU

Any suggestions before I start this and thank you all for your help.

AM



Adrian Mohamed

Script for adding network printer for all users - with user input

$
0
0

Hello - I am trying to create a script which allows user input to add network printers for all users. This is what I have so far but am unable to figure out how to finish. Any help is greatly appreciated Thanks!

@echo off
set Output="c:\"

set /p VarOne=Enter Computer Name:
set /p VarTwo=Enter Print Server:
set /p VarThree=Enter Printer Name:


REM enter your desired output here
echo=%VarOne% >> %Output%\test.txt
echo=%VarTwo% >> %Output%\test.txt
echo=%VarThree% >> %Output%\test.txt


echo.
echo File has been placed %Output%
pause

rundll32 printui.dll,PrintUIEntry /ga /c\\%1 /n\\%2
start /wait sc \\%1 stop spooler
start /wait sc \\%1 start spooler




Having trouble with the Read-Host cmdlet not actually waiting for the user input before moving to the next line in the script.

$
0
0

Hi

I fairly new to this, and I have the following commands working perfectly in the ISE.  Problem is, if I run this in the power shell console (Windows 7), which is what happens when you double click the file, it runs, but it blasts right past the Read-host commands.  In ISE it stops and waits for the input.  Any help?  And feedback on th other suff?  Remember I'm a newbie, be gentle.

#Draft Powershell Script to streamline xxx to yyy migration and reduce the key entry required.  This MUST be run as an administrator or it will fail to configure the IP stack.
#Version 1.0 - Lee Buskey
Set-ExecutionPolicy RemoteSigned
# stuff variable with the current machines hostname.
$hostname = hostname
#Stuff variable to the migration data text file.
$migrationdata = '"c:\migrate\IPDATA.txt"'
# Define the "IP" variable, Read in the master migration data from a text file, and find the line that matches the hostname and stuff it in the variable.
$ip = Select-String -Path "C:\migrate\IPDATA.txt" -Pattern $hostname
# Convert the IP variable contents to a text string value
$ip = $ip.ToString()
#Lop off the first 35 Characters of the IP variable to get rid of junk.
$ip = $ip.Substring(35)
#Trim off any leading spaces..
$ip = $ip.Trim()
#Still working on code to conditinally ask this question if the hostname is not found in the data file.
#$ip = Read-Host “Please enter the IP address for this machine. (xxx.xxx.xxx.xxx.)”
#Populate the DNS server variable
$dns = “10.10.1.10”,”10.10.1.11”
#Populate the Gateway variable
$gateway = “10.10.4.1”
#Populate the Netmask variable
$netmask = “255.255.252.0”
#Populate the DNS suffix variable
$dnsdomain = “new.domain.local”
#clear the screen
cls
#show the user what the script is about to do
Write-Output ("We will be using the following information for the new IP stack","","Hostname:", $hostname,"","IP address","$Ip","","Default Gateway:", $Gateway,"","DNS Servers:", $DNS,"","DNS Suffix:",$DNSdomain,"","")
#Ask the user to confirm the data, or give an option to exit.
$Config = Read-Host “Please press enter if this is correct, and we will apply this configuration. or CTRL-C to exit"
#configure the Ip stack
$Interface = Get-WmiObject win32_networkadapterconfiguration -filter "ipenabled = 'true'"
$Interface.EnableStatic($ip, $netmask)
$Interface.SetGateways("$Gateway", 1)
$Interface.SetDNSServerSearchOrder($dns)
$Interface.SetDNSDomain($dnsdomain)
$Interface.SetDynamicDNSRegistration(“TRUE”)
#Show the user the new IP configuration
ipconfig /allcompartments /all
#add a few line feeds to the screen
Write-Output ("","","")
#Still wroking on code to go here to verify connectivity to new DNS servers before proceeing.  May not be necessary..
#Ask the user of the new config looks right, give an option to exit before trying to join domain.
$Config = Read-Host “We have reconfigured the NIC.  Does the IP configuration for the "Local Area Connection" look right?  Press enter to continue to join the domain, or CTRL-C to exit”



How to run a command line for every folder in a share

$
0
0

I'm trying to use Robocopy to merge two user home directories shares from two different servers to a new server, but the only problem is that I can't use the /purge to mirror deletes because it will delete the other servers stuff (since one server's stuff doesn't exist on the other one currently).

But I'm thinking if someone I could enumerate the folder names from the users$ share on each server, and add it to both path statements in the commands below, i could add purge since then it would be running individually per user folder, rather than at the user level below.

robocopy "\\CurrentServer1\users$" "F:\Users" /E /B /COPY:DATSOU /R:1 /W:1 /MT /LOG:"C:\RobocopyLogs\MirrorUsers1.txt"

robocopy "\\CurrentServer2\users$" "F:\Users" /E /B /COPY:DATSOU /R:1 /W:1 /MT /LOG:"C:\RobocopyLogs\MirrorUsers2.txt

What I'm hoping is that there's some scripting genius out there who could tell me how to use a batch or vbscript to save a LOT of time.  If not, I'm doing this all by hand for hundreds of users :(

Thanks in advance for any help you can provide.

Use the “powercfg” command to change the power plan. - Powershell 3.0

$
0
0

Disable screensaver /

Never turn off display & HDD when using both AC and DC./

Never go to sleep mode including standby and hibernate when using both AC and DC

Need help on creating script to check server certificate expiration

$
0
0

Hi Experts,

I need your help on creating a script for checking certificate expiration for Exchange 2010 and Lync servers.

So far, here's the requirements:

Organize AD or provide some way to interrogate and get an accurate list of Exchange 2010, Lync FE servers

* Script should generate only servers with expiring certificate within 2  weeks

As of now here's the script we're using. But this script gets the server from the text file.

$errLogFile = "ErrorLog.html"
If (Test-Path $errLogFile) {
    Remove-Item $errLogFile
}



#Import-Module ActiveDirectory
$ComputerName = Get-Content "Servers.txt"
#$ComputerName = Get-ADComputer -Filter {OperatingSystem -Like "Windows *Server*"} -SearchBase "OU=SYSTEMS,DC=ASM,DC=LAN" -Properties operatingSystem | Where-Object {$_.DistinguishedName -notlike "*OU=Office Servers,OU=SYSTEMS,DC=ASM,DC=LAN" -and $_.DistinguishedName -notlike "*OU=Desktop Engineering,OU=SYSTEMS,DC=ASM,DC=LAN" -and $_.DistinguishedName -notlike "*OU=Unity,OU=SYSTEMS,DC=ASM,DC=LAN" -and $_.DistinguishedName -notlike "*OU=Retail Voicemail Servers,OU=SYSTEMS,DC=ASM,DC=LAN"} | Select-Object Name | Sort-Object Name | ForEach-Object {$_.Name.ToString()}



$output = Invoke-Command -ComputerName $ComputerName -ScriptBlock {
    Get-ChildItem CERT:\localmachine\my | ForEach-Object {
        $obj = New-Object -TypeName PSObject
        $obj | Add-Member -MemberType NoteProperty -Name ComputerName -Value ([System.Net.Dns]::GetHostName())
        $obj | Add-Member -MemberType NoteProperty -Name FriendlyName -Value $_.FriendlyName
        $obj | Add-Member -MemberType NoteProperty -Name DaysRemaining -Value ($_.NotAfter - (Get-Date)).days
        $obj | Add-Member -MemberType NoteProperty -Name Expiration -Value $_.NotAfter
        $obj | Add-Member -MemberType NoteProperty -Name Subject -Value $_.Subject
        Write-Output $obj
    }

} -ErrorAction SilentlyContinue -ErrorVariable +WRMErr | Select-Object ComputerName, FriendlyName , DaysRemaining, Expiration, Subject | Sort-Object DaysRemaining

#-ErrorAction SilentlyContinue -ErrorVariable +WRMErr | Select-Object ComputerName, FriendlyName , DaysRemaining, Expiration, Subject | Where-Object {$_.DaysRemaining -le 90} | Sort-Object DaysRemaining



$head = "<style>
body {
    font-family:Arial;
}

table {
    border-width: 1px;
    width:800px;
    border-style: solid;
    border-color: black;
    border-collapse: collapse;
}

table th {
    font-size:12px;
    color:white;
    text-align:left;
    border-width: 1px;
    padding: 3px;
    border-style: solid;
    border-color: black;
    background-color:#003366
}

table td {
    font-size:11px;
    border-width: 1px;
    padding: 3px;
    border-style: solid;
    border-color: black
}

table tr:nth-child(odd) {
    background: #CCC
}

table tr:nth-child(even) {
    background: #FFF
}
</style>"
$header = "<B> Cert Report <BR> Date: " + (get-date -format g) + "</B><BR><BR>"
$title = "Cert Report"

If ($output -ne $NULL) {
    $body = $output | ConvertTo-Html -Head $head -Body $header -Title $title | Out-String

    If ($WRMErr) {
        $WRMErr | Select-Object ErrorDetails | ConvertTo-Html -Head $head | Out-File $errLogFile
        Send-MailMessage -to "" -From "" -Subject $title -Body $body -Attachments $errLogFile -BodyAsHtml -SmtpServer server
    } Else {
        Send-MailMessage -to "" -From "" -Subject $title -Body $body -BodyAsHtml -SmtpServer server
    }
}

$WRMErr = $null

Hope you could help me with this and let me know if you have questions. 

Thanks in advance!

Reynald


None


Batch Script Doesnt Work via Folder Lists in a .txt File :(

$
0
0

My batch file is:

:Delete
for /f "delims=" %%f in (7profiledeletelist.txt) do rd /s /q "%%f"
echo deleting finished...
PAUSE
exit

 In "7profiledeletelist.txt", there are :

C:\Users\1* (I tried *.* it didnt work)
C:\Users\2* (I tried *.* it didnt work)
C:\Users\3* (I tried *.* it didnt work)
C:\Users\4* (I tried *.* it didnt work)
C:\Users\5* (I tried *.* it didnt work)
C:\Users\6* (I tried *.* it didnt work)
C:\Users\7* (I tried *.* it didnt work)
C:\Users\8* (I tried *.* it didnt work)
C:\Users\9* (I tried *.* it didnt work)
C:\Users\M* (I tried *.* it didnt work)
C:\Users\T* (I tried *.* it didnt work)

But via this txt, bat file can not delete anything. If I remove * and If I write exact name it's working well.

I want to delete all folders starting with M-T and 1 to 9 in Users. What can I do for "7profiledeletelist.txt"

Is there a mistaken code in batch script? Thank you in advance :(


\_(ツ)_/ twitter.com/serdaruzun

excluding one or some columns in output of Get-process cmdlet doesn't work

$
0
0

hello

in PS 4.0 i need a command so that the output includes all columns except for, one or two columns ? 

for example  get-process cmdlet shows seven columns. i need a cmdlet to show all columns except for handles & cpu columns.

( instead of running Get-process | select -object NPM,PM,WS,VM,CPU,ID )

note: i tested the following command but it still shows handles & cpu columns in the output

( Get-process | select -excludeproperty  handles,cpu )

thanks in advanced

VBS that used to run, does not run anymore when called from CMD file

$
0
0

CMD file:

@echo %~dp0


FORFILES /m %1.d0* /c "cmd /c MetaSuite_OpenFile.vbs @file"

@echo  ****%1.d0* **** ****

result:

C:\Users\red\DOCUME~1\METASU~1\GENFUJ~1\TMP\;
C:\Users\red\Documents\Metasuite\GENFujitsu_Windows\TMP>FORFILES /m azert.d0* /c "cmd /c MetaSuite_OpenFile.vbs @file" ;
 ****azert.d0* **** ****;

VBS file is in same directory:

C:\Users\red\Documents\Metasuite\GenFujitsu_Windows\TMP

runs fine from command prompt

and used to run!!

I'm running windows 7

thank you for your help!

Batch Script Doesnt Delete Folders in a FolderList .txt File :(

$
0
0

My batch file is:

:Delete
for /f "delims=" %%f in (7profiledeletelist.txt) do rd /s /q "%%f"
PAUSE
exit

 In "7profiledeletelist.txt", there are :

C:\Users\1* (I tried *.* it didnt work)
C:\Users\2* (I tried *.* it didnt work)
C:\Users\3* (I tried *.* it didnt work)
C:\Users\4* (I tried *.* it didnt work)
C:\Users\5* (I tried *.* it didnt work)
C:\Users\6* (I tried *.* it didnt work)
C:\Users\7* (I tried *.* it didnt work)
C:\Users\8* (I tried *.* it didnt work)
C:\Users\9* (I tried *.* it didnt work)
C:\Users\M* (I tried *.* it didnt work)
C:\Users\T* (I tried *.* it didnt work)

But via this txt, bat file can not delete anything. If I remove * and If I write exact name it's working well.

I want to delete all folders starting with M-T and 1 to 9 in Users. How can I change  "7profiledeletelist.txt" or batch command? Is there a mistaken code in batch script? Thank you in advance :(


\_(ツ)_/ twitter.com/serdaruzun



Why "XML is invalid" when Get-CimInstance is supplied with -ComputerName?

$
0
0

I've been googling around for 10 days but can't seem to find the right answer. My laptop is part of an AD DS domain. I use it to explore/develop tools in PowerShell and WMI. I noticed when I tried to gather the system information via Win32_ComputerSystem I got the following error:

PS C:\Users\jsung> Get-CimInstance -ClassName Win32_ComputerSystem -ComputerName jsung03-pc
Get-CimInstance : The WS-Management service cannot process the request because the XML is invalid.
At line:1 char:1
+ Get-CimInstance -ClassName Win32_ComputerSystem -ComputerName jsung03-pc
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ParserError: (root\cimv2:Win32_ComputerSystem:String) [Get-CimInstance], CimException
    + FullyQualifiedErrorId : HRESULT 0x80338043,Microsoft.Management.Infrastructure.CimCmdlets.GetCimInstanceCommand
    + PSComputerName        : jsung03-pc

jsung03-pc is the hostname of my laptop. I loaded RSAT 4.0 recently and WinRM and WsMAN were enabled via Enable-PSRemoting.

PS C:\Users\jsung> $PSVersionTable.PSVersion
Major  Minor  Build  Revision
-----  -----  -----  --------
4      0      -1     -1

PS C:\Users\jsung> Get-Service wi*
Status   Name               DisplayName
------   ----               -----------
Stopped  WinDefend          Windows Defender
Running  WinHttpAutoProx... WinHTTP Web Proxy Auto-Discovery Se...
Running  Winmgmt            Windows Management Instrumentation
Running  WinRM              Windows Remote Management (WS-Manag...

If I removed the "-ComputerName jsung03-pc" the cmdlet returned outcome w/o error:

PS C:\Users\jsung> Get-CimInstance -ClassName Win32_ComputerSystem
Name             PrimaryOwnerName         Domain                   TotalPhysicalMemory      Model                  Manufacturer
----             ----------------         ------                   -------------------      -----                  ------------
JSUNG03-PC       ntapadmin           <domain.com>            4147822592               4384BE6                 LENOVO

I don't see this issue in the "Win32_Process" class. Test-WSMan shows the system is running 3.0.

PS C:\Users\jsung> Test-WSMan -ComputerName jsung03-pc -Authentication Default
wsmid           : http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd
ProtocolVersion : http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd
ProductVendor   : Microsoft Corporation
ProductVersion  : OS: 6.1.7601 SP: 1.0 Stack: 3.0

Wonder if anyone could shed some light what the root cause may be and how to fix this? 

Thanks!

findstr | IF found | do something

$
0
0

Hi Guys,

I need an urgent help. I'm trying to achieve below:

open the file
search for "string123"
if found do "some java commmand"
save result in the file
else exit

also as far as I'm going to do this every 4 min in the production environment then I want my batch script to skip the ones which it already has found before so that it just check the last occurrence only because everytime it search from the beginning of the file.  

then I was thinking about something like this below. does it make sense?


open the file
search for "string123"
if found 
compare the line with %lastInstance%
if success 
set the line to variable %lastInstance%
do jmap
save result
else exit
exit

would you kindly give me sample code that I can try? thanks a lot. I have done googling and searching around but still could not manage it. as I need it fast then i thought to write here....

hope you can help me quickly



Launching Visio 2003 file via Powershell 3.0 is slow

$
0
0

Hello fellows,

I took one of the sample PS scripts from the Scripting Guy posts and adapted it to my needs. This script basically launches Visio 2003, and opens a new file that is based on a specified template with all required stencils. The problem is that when I launch the PS script, the PS window opens and then there is a delay of ~10 seconds until Visio is launched. For some reason, the script execution is too slow. I've upgraded PS to version 3.0 but it did not help. I am using Win 7 Enterprise. 

Any ideas how it is possible to speed up the PS script execution?

Here is the script:

$application = New-Object -ComObject Visio.Application
$application.visible = $true
$documents = $application.Documents 
$document = $documents.Add("C:\Users\myname\Documents\My Shapes\Visio_Template.vst") 
$pages = $application.ActiveDocument.Pages 
$page = $pages.Item(1) 
$document.SaveAs("C:\Users\myname\Test\Diagram.vsd") 


Thank you in advance!

service

$
0
0

Hi Everybody,

   Is it possible to determine running services and stopped services in windows through command?

thanks

Powershell Script to Multiple Servers

$
0
0

I have this script that I would like to push to 15 servers in my lab to save a lot of time. When I go to server manager and select multiple servers and select powershell it just gives me 15 different windows. I would like to send the script below to all 15 servers. How can I go about doing this? I saw something about the invoke command, however, I don't completely understand it. It seems good for "get" data but not so much for sending it? Could someone please help me understand this a little better. I have lots of powershell scripts I am excited to try but sending it to one server at a time still seems to defeat the purpose.

Servers are named NTASRV-01,NTASRV-02,NTASRV-03... and so on

$env = $env:computername

$a = $env.Substring($env.length -2, 2)

$vhdname = "VHDD"

$parent = "GoldenImage"

$vhd1 = $vhdname + ($a + 1)

$vhd2 = $vhdname + ($a + 2)

$vhd3 = $vhdname + ($a + 3)

$vhd4 = $vhdname + ($a + 4)

New-VHD -ParentPath C:\VHD\$parent.vhd -Differencing -Path C:\vhd\$vhd1.vhd

New-VHD -ParentPath C:\VHD\$parent.vhd -Differencing -Path C:\vhd\$vhd2.vhd

New-VHD -ParentPath C:\VHD\$parent.vhd -Differencing -Path C:\vhd\$vhd3.vhd

New-VHD -ParentPath C:\VHD\$parent.vhd -Differencing -Path C:\vhd\$vhd4.vhd

$VMname = "VM"

$SWname = "Primary"

$VM1 = $VMname + ($a + 1)

$VM2 = $VMname + ($a + 2)

$VM3 = $VMname + ($a + 3)

$VM4 = $VMname + ($a + 4)

New-VM -Name $VM1 -VHDPath c:\vhd\$vhd1.vhd -SwitchName $SWname -MemoryStartupBytes 1GB

New-VM -Name $VM2 -VHDPath c:\vhd\$vhd2.vhd -SwitchName $SWname -MemoryStartupBytes 1GB

New-VM -Name $VM3 -VHDPath c:\vhd\$vhd3.vhd -SwitchName $SWname -MemoryStartupBytes 1GB

New-VM -Name $VM4 -VHDPath c:\vhd\$vhd4.vhd -SwitchName $SWname -MemoryStartupBytes 1GB 

Viewing all 15028 articles
Browse latest View live


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